Skip to content
This repository was archived by the owner on Jul 7, 2022. It is now read-only.

Commit 0295768

Browse files
committed
Update demo for sync
1 parent 57ad66d commit 0295768

File tree

2 files changed

+90
-10
lines changed

2 files changed

+90
-10
lines changed

demo/app/main-page.js

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
var sqlite = require('nativescript-sqlite');
2-
var ObservableArray = require("data/observable-array").ObservableArray;
1+
const sqlite = require('nativescript-sqlite');
2+
const ObservableArray = require("tns-core-modules/data/observable-array").ObservableArray;
33

44

55
//var Tracing = require('./tracing.js');
@@ -22,14 +22,21 @@ if (sqlite.HAS_COMMERCIAL) {
2222

2323
if (sqlite.HAS_ENCRYPTION) {
2424
console.log("Using Encryption");
25-
dbname = 'encrypted.sqlite';
25+
//dbname = 'encrypted.sqlite';
2626
data.push({name:'Encryption Support', css:'one'});
2727
} else {
2828
console.log("No Encryption");
2929
}
3030
data.push({name: 'Loading...', css: 'one'});
3131

3232

33+
if (sqlite.HAS_SYNC) {
34+
console.log("Using Sync");
35+
data.push({name: 'Sync Support',css: 'one'});
36+
} else {
37+
console.log("No Sync");
38+
}
39+
3340

3441
exports.pageLoaded = function(args) {
3542
page = args.object;
@@ -38,7 +45,7 @@ exports.pageLoaded = function(args) {
3845
if (!sqlite.exists(dbname)) {
3946
sqlite.copyDatabase(dbname);
4047
}
41-
new sqlite(dbname, {key: 'testing', multithreading: !!sqlite.HAS_COMMERCIAL, migrate: true}, function(err, dbConnection) {
48+
new sqlite(dbname, {zkey: 'testing', multithreading: false /* !!sqlite.HAS_COMMERCIAL */, migrate: true}, function(err, dbConnection) {
4249
if (err) {
4350
console.log(err, err.stack);
4451
}
@@ -62,22 +69,59 @@ exports.pageLoaded = function(args) {
6269
};
6370

6471
exports.addNewName = function() {
65-
var entry = page.getViewById('entry');
66-
var name = entry.text;
72+
const entry = page.getViewById('entry');
73+
const name = entry.text;
6774
if (name.length > 0) {
6875
if (name.toLowerCase() === "test" || name.toLowerCase() === "runtest" || name.toLowerCase() === "tests" || name.toLowerCase() === "runtests" || name.indexOf("Test") === 0) {
6976
runTests();
7077
return;
7178
}
7279

80+
if (name.toLowerCase() === "sync") {
81+
db.enableTracking("names", {'syncTime': 10}).then((res) => {
82+
console.log("Result", res);
83+
}).catch((err) => {
84+
console.log("Error",err, err.stack);
85+
});
86+
return;
87+
}
88+
89+
if (name.toLowerCase() === "fsync") {
90+
db.enableTracking("names", {force: true, syncTime: 10}).then((res) => {
91+
console.log("Result", res);
92+
}).catch((err) => {
93+
console.log("Error",err, err.stack);
94+
});
95+
return;
96+
}
97+
98+
if (name.toLowerCase() === "csync") {
99+
db.execSQL("update __mt_sync_tracking set completed=1");
100+
return;
101+
}
102+
103+
104+
if (name.toLowerCase() === "dsync") {
105+
db.execSQL("delete from __mt_sync_tracking");
106+
return;
107+
}
108+
109+
if (name.toLowerCase() === 'tsync') {
110+
db.all("select * from __mt_sync_tracking").then((res) => {
111+
console.log("Results:", res);
112+
});
113+
return;
114+
}
115+
116+
73117
db.execSQL("insert into names (name) values (?)", name);
74118
reloadData();
75119
}
76120
entry.text = '';
77121
};
78122

79123
exports.openMT = function() {
80-
const utils = require('utils/utils');
124+
const utils = require('tns-core-modules/utils/utils');
81125
utils.openUrl("https://www.master-technology.com");
82126
};
83127

@@ -410,7 +454,19 @@ function setupPreparedTests(callback) {
410454
callback();
411455
return;
412456
}
413-
console.log("!--------- Creating Prepared Tests Data");
457+
458+
console.log("!--------- Creating Prepared Tests Data");
459+
db.execSQL(['drop table if exists preparetests;','create table preparetests (`int_field` integer, `num_field` numeric, `real_field` real, `text_field` text)'], function (err) {
460+
if (err) {
461+
data.push({name: 'Failed to create tables and data...', css: 'one'});
462+
console.log("!---- Create Table err", err);
463+
return;
464+
}
465+
callback();
466+
});
467+
468+
469+
/*
414470
db.execSQL('drop table if exists preparetests;', function (err) {
415471
if (err) {
416472
console.log("!---- Drop Err", err);
@@ -423,7 +479,7 @@ function setupPreparedTests(callback) {
423479
}
424480
callback();
425481
});
426-
});
482+
}); */
427483
}
428484

429485
function runPreparedTests(callback) {
@@ -437,7 +493,7 @@ function runPreparedTests(callback) {
437493
setupPreparedTests(function() {
438494
createPreparedData(true, function () {
439495

440-
var tests = [{
496+
let tests = [{
441497
name: 'Verify Rollback Check',
442498
sql: 'select count(*) from preparetests',
443499
results: [0],

demo/app/sqlite_syncer.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/************************************************************************************
2+
* (c) 2019 Master Technology
3+
* Licensed under the MIT license or contact me for a support, changes, enhancements,
4+
* and/or if you require a commercial licensing
5+
*
6+
* Any questions please feel free to email me or put a issue up on github
7+
* Nathan@master-technology.com http://nativescript.tools
8+
* Version 1.0.0 - Sync
9+
***********************************************************************************/
10+
11+
module.exports = {
12+
db: null,
13+
setup: function(db) {
14+
console.log("Syncer Setup");
15+
this.db = db;
16+
},
17+
handleSync: function(res, callback) {
18+
console.log("Handle Sync", res);
19+
// TODO: Send records to remote server, upon getting notified that records are good; run the "Callback()"
20+
21+
// currently during testing, lets just Sending a False back will say the records are NOT done...
22+
callback(false);
23+
}
24+
};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy