igorizr1 / wSQL

wSQL - angularJS active record module for WebSQLite database - database in the browser. U can persist your data for your PhoneGap HTML5 applications build with ionic or angular. Good solution for mobile applications with offline mode.
http://igorizr1.github.io/wSQL/
34 stars 8 forks source link

cordova sqlite plugin #5

Open fdjean opened 9 years ago

fdjean commented 9 years ago

To use with websql or sqlite (ionic, cordova plugin) line 88:

db = window.openDatabase(db_params.name, db_params.version, db_params.sub_name, db_params.size);

To (not fully tested):

if (window.cordova) {
    $ionicPlatform.ready(function () {
        db = $cordovaSQLite.openDB(db_params);
    });
} else {
    db = window.openDatabase(db_params);
}

Passing a open params (object) I can use https://github.com/litehelpers/Cordova-sqlcipher-adapter with customs options

And to finish :smirk: line 82:

var db, db_set = false;

db_set is a dead variable ?

igorizr1 commented 9 years ago

Hi, thank you a lot for contribution

Agree on adding callback for device or document ready.

However in future releases I'm planning to remove angular dependency and make library stand alone. For angular there will be a plugin.

Anyway, I will add something for this in next release. Also if u want to send some improvements in PR will appreciate

fdjean commented 9 years ago

I'm not comfortable with Git and Github, so I publish here for now ;)

Tested OK for websql desktop (chrome), websql & sqlite mobile (android cordova plugin sqlcipher) https://github.com/litehelpers/Cordova-sqlcipher-adapter

For SQLite mobile:

.factory('wSQL', function (W_SQL_CONFIG, $q) {
TO
.factory('wSQL', function (W_SQL_CONFIG, $q, $ionicPlatform, $cordovaSQLite) {

And

var Db = (function () {
    var db, db_set = false;
    return {
        get: function () {
            return db;
        },
        set: function (db_params) {
            db = window.openDatabase(db_params.name, db_params.version, db_params.sub_name, db_params.size);
            db_set = true;
            return db;
        }
    }
}
TO
var Db = (function () {
    var db = false;
    return {
        get: function () {
            return db;
        },
        set: function (db_params) {
            if (window.cordova) {
                $ionicPlatform.ready(function () {
                    db = $cordovaSQLite.openDB(db_params);
                    // websql mobile
                    // db = window.openDatabase(db_params.name, db_params.version, db_params.sub_name, db_params.size); 
                });
            } else {
                db = window.openDatabase(db_params.name, db_params.version, db_params.sub_name, db_params.size);
            }
            return db;
        }
    }
}

To have multiple insertions with the same order as array:

InsertQuery.prototype.batch_insert_query = function(table, data, ignore){
    ...
    sql +=  ' UNION SELECT '+row_sql.query;
    ...
};
To
InsertQuery.prototype.batch_insert_query = function(table, data, ignore){
    ...
    sql +=  ' UNION ALL SELECT '+row_sql.query;
    ...
};
igorizr1 commented 9 years ago

Right, good suggestion. However this means that library will require ionic as dependency.

Do u think it will work the same fine if using just device.ready instead of $ionicPlatform.ready ?

fdjean commented 9 years ago

http://forum.ionicframework.com/t/local-storage-not-instantly-available/27285

mukeshp004 commented 8 years ago

Hey this plugin is not working with the below mentioned code in android app.

var Db = (function () { var db = false; return { get: function () { return db; }, set: function (db_params) { if (window.cordova) { $ionicPlatform.ready(function () { db = $cordovaSQLite.openDB(db_params); // websql mobile // db = window.openDatabase(db_params.name, db_params.version, db_params.sub_name, db_params.size); }); } else { db = window.openDatabase(db_params.name, db_params.version, db_params.sub_name, db_params.size); } return db; } }