How to use nativescript-sqlite - 10 common examples

To help you get started, we’ve selected a few nativescript-sqlite examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NathanaelA / nativescript-sqlite / demo / app / main-page.js View on Github external
function runNativeObjectTest(callback) {
	console.log("!--------------  Starting RNO Test");
	db.resultType(sqlite.RESULTSASOBJECT);
	db.valueType(sqlite.VALUESARENATIVE);

	const tests = [
		// Callback
		{name: 'NativeObject Get', sql: 'select * from tests where int_field=?', values: [2], results: {int_field: 2, num_field: 4.8, real_field: 5.6, text_field: 'Text2'}, use: 0},
		{name: 'NativeObject All', sql: 'select * from tests order by int_field', results: [{int_field: 1, num_field: 1.2, real_field: 2.4, text_field: 'Text1'},{int_field: 2, num_field: 4.8, real_field: 5.6, text_field: 'Text2'}], use: 1},
		{name: 'NativeObject Each', sql: 'select * from tests order by int_field', results: [{int_field: 1, num_field: 1.2, real_field: 2.4, text_field: 'Text1'},{int_field: 2, num_field: 4.8, real_field: 5.6, text_field: 'Text2'}], use: 2},

		// Promise
		{name: 'NativeObject Promise Get', sql: 'select * from tests where int_field=?', values: [2], results: {int_field: 2, num_field: 4.8, real_field: 5.6, text_field: 'Text2'}, use: 3},
		{name: 'NativeObject Promise All', sql: 'select * from tests order by int_field', results: [{int_field: 1, num_field: 1.2, real_field: 2.4, text_field: 'Text1'},{int_field: 2, num_field: 4.8, real_field: 5.6, text_field: 'Text2'}], use: 4},
		{name: 'NativeObject Promise Each', sql: 'select * from tests order by int_field', results: [{int_field: 1, num_field: 1.2, real_field: 2.4, text_field: 'Text1'},{int_field: 2, num_field: 4.8, real_field: 5.6, text_field: 'Text2'}], use: 5}

	];
	runTestGroup(tests, callback);
}
github NathanaelA / nativescript-sqlite / demo / app / main-page.js View on Github external
function runStringObjectTest(callback) {
	console.log("!--------------  Starting RSO Test");
	db.resultType(sqlite.RESULTSASOBJECT);
	db.valueType(sqlite.VALUESARENATIVE);

	const tests = [
		// Callback
		{name: 'StringObject Get', sql: 'select * from tests where int_field=?', values: [2], results: {int_field: "2", num_field: "4.8", real_field: "5.6", text_field: 'Text2'}, use: 0},
		{name: 'StringObject All', sql: 'select * from tests order by int_field', results: [{int_field: "1", num_field: "1.2", real_field: "2.4", text_field: 'Text1'},{int_field: "2", num_field: "4.8", real_field: "5.6", text_field: 'Text2'}], use: 1},
		{name: 'StringObject Each', sql: 'select * from tests order by int_field', results: [{int_field: "1", num_field: "1.2", real_field: "2.4", text_field: 'Text1'},{int_field: "2", num_field: "4.8", real_field: "5.6", text_field: 'Text2'}], use: 2},

		// Promise
		{name: 'StringObject Promise Get', sql: 'select * from tests where int_field=?', values: [2], results: {int_field: "2", num_field: "4.8", real_field: "5.6", text_field: 'Text2'}, use: 3},
		{name: 'StringObject Promise All', sql: 'select * from tests order by int_field', results: [{int_field: "1", num_field: "1.2", real_field: "2.4", text_field: 'Text1'},{int_field: "2", num_field: "4.8", real_field: "5.6", text_field: 'Text2'}], use: 4},
		{name: 'StringObject Promise Each', sql: 'select * from tests order by int_field', results: [{int_field: "1", num_field: "1.2", real_field: "2.4", text_field: 'Text1'},{int_field: "2", num_field: "4.8", real_field: "5.6", text_field: 'Text2'}], use: 5}

	];
	runTestGroup(tests, callback);
}
github Appverse / Nativescript-NG2-Showcase / app / pages / database / database.component.ts View on Github external
public openDB(){
        let instance= this;
        //CHECK IF IT EXISTS AND IF ITS OPEN
        if(Sqlite.exists("MyDB")){
            if(instance.db.isOpen()){
                console.log("DB is already open!");
                instance.info = "DB is already open!";
            } else {
                var db_promise = new Sqlite("MyDB", false, (err, db)=>{
                    if (err) { 
                    console.error("We failed to open database", err);
                    instance.info = "We failed to open database " + err;
                    } else {
                    console.log("Are we open yet (Inside Callback)? ", db.isOpen() ? "Yes" : "No"); // Yes
                    instance.info = "DB opened";
                    instance.db = db;
                    }
                });
            }
github NathanaelA / nativescript-sqlite / demo / app / main-page.js View on Github external
function runNativeObjectTest(callback) {
	console.log("!--------------  Starting RNO Test");
	db.resultType(sqlite.RESULTSASOBJECT);
	db.valueType(sqlite.VALUESARENATIVE);

	const tests = [
		// Callback
		{name: 'NativeObject Get', sql: 'select * from tests where int_field=?', values: [2], results: {int_field: 2, num_field: 4.8, real_field: 5.6, text_field: 'Text2'}, use: 0},
		{name: 'NativeObject All', sql: 'select * from tests order by int_field', results: [{int_field: 1, num_field: 1.2, real_field: 2.4, text_field: 'Text1'},{int_field: 2, num_field: 4.8, real_field: 5.6, text_field: 'Text2'}], use: 1},
		{name: 'NativeObject Each', sql: 'select * from tests order by int_field', results: [{int_field: 1, num_field: 1.2, real_field: 2.4, text_field: 'Text1'},{int_field: 2, num_field: 4.8, real_field: 5.6, text_field: 'Text2'}], use: 2},

		// Promise
		{name: 'NativeObject Promise Get', sql: 'select * from tests where int_field=?', values: [2], results: {int_field: 2, num_field: 4.8, real_field: 5.6, text_field: 'Text2'}, use: 3},
		{name: 'NativeObject Promise All', sql: 'select * from tests order by int_field', results: [{int_field: 1, num_field: 1.2, real_field: 2.4, text_field: 'Text1'},{int_field: 2, num_field: 4.8, real_field: 5.6, text_field: 'Text2'}], use: 4},
		{name: 'NativeObject Promise Each', sql: 'select * from tests order by int_field', results: [{int_field: 1, num_field: 1.2, real_field: 2.4, text_field: 'Text1'},{int_field: 2, num_field: 4.8, real_field: 5.6, text_field: 'Text2'}], use: 5}

	];
	runTestGroup(tests, callback);
}
github NathanaelA / nativescript-sqlite / demo / app / main-page.js View on Github external
function runNativeArrayTest(callback) {
	console.log("!--------------  Starting RNA Test");
	db.resultType(sqlite.RESULTSASARRAY);
	db.valueType(sqlite.VALUESARENATIVE);

	const tests = [
		// Callback
		{name: 'NativeArray Check', sql: 'select count(*) from tests', results: [2], use: 0},
		{name: 'NativeArray Get', sql: 'select * from tests where int_field=?', values: [2], results: [2,4.8,5.6,'Text2'], use: 0},
		{name: 'NativeArray All',    sql: 'select * from tests order by int_field', results: [[1,1.2,2.4,"Text1"],[2,4.8,5.6,'Text2']], use: 1},
		{name: 'NativeArray Each', sql: 'select * from tests order by int_field', results: [[1,1.2,2.4,"Text1"],[2,4.8,5.6,'Text2']], use: 2},

		// Promise
		{name: 'NativeArray Promise Check', sql: 'select count(*) from tests', results: [2], use: 3},
		{name: 'NativeArray Promise Get', sql: 'select * from tests where int_field=?', values: [2], results: [2,4.8,5.6,'Text2'], use: 3},
		{name: 'NativeArray Promise All',    sql: 'select * from tests order by int_field', results: [[1,1.2,2.4,"Text1"],[2,4.8,5.6,'Text2']], use: 4},
		{name: 'NativeArray Promise Each', sql: 'select * from tests order by int_field', results: [[1,1.2,2.4,"Text1"],[2,4.8,5.6,'Text2']], use: 5}

	];
github NathanaelA / nativescript-sqlite / demo / app / main-page.js View on Github external
function runStringArrayTest(callback) {
	console.log("!--------------  Starting RSA Test");
	db.resultType(sqlite.RESULTSASARRAY);
	db.valueType(sqlite.VALUESARESTRINGS);
	const tests = [
		// Callback Version
		{name: 'StringArray Get', sql: 'select * from tests where int_field=?', values: [2], results: ["2","4.8","5.6",'Text2'], use: 0},
		{name: 'StringArray All', sql: 'select * from tests order by int_field', results: [["1","1.2","2.4","Text1"],["2","4.8","5.6",'Text2']], use: 1},
		{name: 'StringArray Each', sql: 'select * from tests order by int_field', results: [["1","1.2","2.4","Text1"],["2","4.8","5.6",'Text2']], use: 2},

		// Promise Version
		{name: 'StringArray Promise Get', sql: 'select * from tests where int_field=?', values: [2], results: ["2","4.8","5.6",'Text2'], use: 3},
		{name: 'StringArray Promise All', sql: 'select * from tests order by int_field', results: [["1","1.2","2.4","Text1"],["2","4.8","5.6",'Text2']], use: 4},
		{name: 'StringArray Promise Each', sql: 'select * from tests order by int_field', results: [["1","1.2","2.4","Text1"],["2","4.8","5.6",'Text2']], use: 5}
	];
	runTestGroup(tests, callback);
}
github Appverse / Nativescript-NG2-Showcase / app / pages / database / database.component.ts View on Github external
public setupDB() {
        this.db.resultType(Sqlite.RESULTSASOBJECT);
        this.db.execSQL('DROP TABLE IF EXISTS tests;', (err)=>{
            if (err) { console.log("!---- Drop Err", err); }
            this.db.execSQL('CREATE TABLE tests (`name` TEXT, `age` NUMERIC)', (err)=>{
                if (err) {
                    console.log("!---- Create Table err", err);
                    return;
                }
                this.db.execSQL('INSERT INTO tests (name, age) VALUES ("Nathan Drake",32)', (err, id)=>{
                    if (err) {
                        console.log("!---- Insert err", err);
                        return;
                    }
                this. db.execSQL('INSERT INTO tests (name, age) VALUES ("Elena Fisher",30)');
                });
            });
        });
github bradyhouse / house / fiddles / nativeScript / fiddle-0009-SqliteDb / puzzle / platforms / ios / puzzle / app / shared / db.service.js View on Github external
function onSelectHighScores(db, fn, scope) {
  consoleLogMsg("db.service", "onSelectHighScore");
  if (db) {
    db.resultType(Sqlite.RESULTSASOBJECT);
    db.valueType(Sqlite.VALUESARENATIVE);
    db.all(sql.selectHighScore, function (err, items) {
      data.length = 0;
      if (err) {
        console.error(err);
      } else {
        if (items && items.length) {
          items.forEach(function (item, index) {
            var record = createHighScoreRecord(item);
            consoleLogRecord(index, record);
            data.push(record);
          });
        }
        if (typeof fn === "function") {
          if (scope) {
            fn.apply(scope, [data]);
github NathanaelA / nativescript-sqlite / demo / app / main-page.js View on Github external
exports.pageLoaded = function(args) {
	page = args.object;
	page.bindingContext = {names: data};

	if (!sqlite.exists(dbname)) {
		sqlite.copyDatabase(dbname);
	}
	new sqlite(dbname, {key: 'testing', multithreading: !!sqlite.HAS_COMMERCIAL, migrate: true}, function(err, dbConnection) {
		if (err) {
			console.log(err, err.stack);
		}
		db = dbConnection;
		db.resultType(sqlite.RESULTSASOBJECT);

		db.version().then(function (results) {
			console.log("User Version: ", results, typeof results, Number.isNumber(results)); //, String.isString(results));
		});

		if (sqlite.HAS_ENCRYPTION) {
			db.get("PRAGMA cipher_version;").then(function(results) {
				console.log("Cipher version", results['cipher_version']);
github Appverse / Nativescript-NG2-Showcase / app / pages / database / database.component.ts View on Github external
public closeDB(){
        let instance = this;
        //CHECK IF IT EXISTS AND IF ITS OPEN
        if(Sqlite.exists("MyDB")){
            if(this.db.isOpen()){
                this.db.close((err)=>{
                    if(err){
                        console.log("We failed to close database");
                    } else {
                        console.log("DB closed");
                        instance.info = "DB closed";
                    }
                })
            } else {
                console.log("DB is already closed!");
                instance.info = "DB is already closed!";
            }
            
        } else {
            console.log("DB doesn't exist");