SQLite Development in Ionic 3

Share

What is it?

Cordova SQLite is a cross-platform storage plugin for Ionic based on HTML5/ Web SQL API.

It comes with basic features like creating / deleting / opening databases, and executing SQL scripts.

Currently it only supports native platforms which can influence debugging and testing time while developing Ionic apps.


Usage

The steps of using this plugin requires you first to create or open the database

  this.sqlite.create({
        name: "database_name.db", // name of the desired database
        location: "default" // needs this parameter for iOS devices
    })

This will search and open the database or it will create it on the spot if not found.

The function will return a promise which we will use it to execute sql.

.then((db: SQliteObject ) => {

        db.executeSql("SQL STATEMENT", [ "VARIABLES NEEDED" ])
            .then(() => console.log('Executed SQL'))
            .catch(e => console.log(e));
});

The executeSql function also returns a promise which must be fullfiled, but since we are not doing anything else right now, we will use it to log our success or catch any errors that might have arisen while trying to execute our statement.

More statements can be chained together in promises, like creating the table and executing other functions on it.


Caveats

One thing I could take away from this plugin is that while working with it, you realize that after creating a table and developing the C.R.U.D. ( CREATE, READ, UPDATE, DELETE ) functions you will come to the realization that if you need to change something in the structure of your table you will have to change it in 7 other regions of your code which can lead to confusing bugs and hard debugging sessions along the way.

More informations can on the offical site of Ionic framework here.


Conclusions

Since this plugin is the only good offer on the table, for having a local database storage on your Ionic 3, app it’s fairly ok to say that it’s useful, even though it can provoke some head scratching bugs. More development on it is needed for it to be really good. For now I am happy about it and cooking a good library for it.

More details soon…

By continuing to use the site, you agree to the use of cookies. More information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close