Search code examples
sqliteindexeddbintel-xdk

IndexedDB or SQLite for internal database developing on Intel XDK


I already have the webapp which will be convert to mobile app through Intel XDK but I dont know what option to choose regarding databases, I wanted to learn more about SQLite for this but I saw in some articles that SQLite is deprecated for this goal, am I wrong?

On the other hand is IndexedDB which I just read about today

I can´t find fresh info about this doubt, can you advice me please?


Solution

  • I would suggest using IndexedDB rather than SQLite. I found it difficult to find a proper plugin for SQLite which is still supported and has some useful documentation.

    I found a excellent plugin with excellent documentation also and support from the author for IndexedDB. It is called Dexie and is described as a A Minimalistic Wrapper for IndexedDB. It also has a Github page which is located here.

    Example

    Some examples taken from their site.

    Database Connection:

    /*
    |----------------------------|
    | Make a database connection |
    |----------------------------|
    */
    
    var db = new Dexie('MyDatabase');
    
    // Define a schema
    db.version(1).stores({
        friends: 'name, age'
    });
    
    
    // Open the database
    db.open().catch(function(error) {
        alert('Uh oh : ' + error);
    });
    

    Executing Queries:

    /*
    |-----------------------|
    | Then run some queries |
    |-----------------------|
    */
    
    // Find some old friends
    db.friends
        .where('age')
        .above(75)
        .each (function (friend) {
            console.log (friend.name);
        });
    
    // or make a new one
    db.friends.add({
        name: 'Camilla',
        age: 25
    });