Skip to content

Commit

Permalink
demo
Browse files Browse the repository at this point in the history
  • Loading branch information
juanchinovas committed Apr 16, 2022
1 parent ba6c812 commit 4826359
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 159 deletions.
13 changes: 0 additions & 13 deletions demo/.migration_backup/_backup.json

This file was deleted.

6 changes: 0 additions & 6 deletions demo/.migration_backup/app/package.json

This file was deleted.

29 changes: 0 additions & 29 deletions demo/.migration_backup/package.json

This file was deleted.

10 changes: 0 additions & 10 deletions demo/.migration_backup/webpack.config.js

This file was deleted.

4 changes: 2 additions & 2 deletions demo/app/home/home-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { NavigatedData, Page } from "@nativescript/core";
import { HomeViewModel } from "./home-view-model";

export function onNavigatingTo(args: NavigatedData) {
const page = <Page>args.object;
const page = <Page>args.object;

page.bindingContext = new HomeViewModel();
page.bindingContext = new HomeViewModel();

}
138 changes: 69 additions & 69 deletions demo/app/home/home-view-model.ts
Original file line number Diff line number Diff line change
@@ -1,85 +1,85 @@
import { Observable } from "@nativescript/core";
import {DbBuilder, IDatabase, DbCreationOptions} from 'nativescript-sqlite-access';
import { DbBuilder, IDatabase, DbCreationOptions } from "nativescript-sqlite-access";
import { databaseName, creationTableQueries, dropTableQueries, databaseTables } from "../db-setting";

export class HomeViewModel extends Observable {
private db: IDatabase;
private updateCounter = 0;
constructor() {
super();
this.db = DbBuilder(databaseName, <DbCreationOptions>{
version: 1,
createTableScriptsFn: () => creationTableQueries,
dropTableScriptsFn: () => dropTableQueries
});
private db: IDatabase;
private updateCounter = 0;
constructor() {
super();
this.db = DbBuilder(databaseName, <DbCreationOptions>{
version: 1,
createTableScriptsFn: () => creationTableQueries,
dropTableScriptsFn: () => dropTableQueries
});

this.set('text', '');
this.set('hint', 'Name something here');
this.set('items', []);
this.reload();
}
this.set("text", "");
this.set("hint", "Name something here");
this.set("items", []);
this.reload();
}


addText() {
let id = this.db.insert(databaseTables.PERSONS, {
name: this.get('text'),
n: 45.5,
i: 1 * ++this.updateCounter
});
console.log("id", id);
this.set('text', '');
this.reload();
}
addText() {
const id = this.db.insert(databaseTables.PERSONS, {
name: this.get("text"),
n: 45.5,
i: 1 * ++this.updateCounter
});
console.log("id", id);
this.set("text", "");
this.reload();
}

remove(event) {
this.db.beginTransact();
let test = this.get("items")[event.index];
let deleted = this.db.delete(databaseTables.PERSONS, '_id=?', [test._id]);
console.log("deleted count.: ", deleted);
this.db.commit();
this.update();
this.reload();
}
remove(event) {
this.db.beginTransact();
const test = this.get("items")[event.index];
const deleted = this.db.delete(databaseTables.PERSONS, "_id=?", [ test._id ]);
console.log("deleted count.: ", deleted);
this.db.commit();
this.update();
this.reload();
}

update() {
const updated = this.db.update(databaseTables.PERSONS, {
name: "updateName-" + (this.updateCounter++)
}, "_id=?", [1]);
console.log("updated:", updated);
}
update() {
const updated = this.db.update(databaseTables.PERSONS, {
name: "updateName-" + (this.updateCounter++)
}, "_id=?", [ 1 ]);
console.log("updated:", updated);
}

reload() {
this.db.select(`SELECT * FROM ${databaseTables.PERSONS}`).process()
.then(result => {
this.set('items', result);
})
.catch(console.error);
reload() {
this.db.select(`SELECT * FROM ${databaseTables.PERSONS}`).process()
.then(result => {
this.set("items", result);
})
.catch(console.error);

const reducerFn = (acc, next) => {
acc["name"] = acc["name"] || [];
acc["name"].push(next.name);
return acc;
};
const reducerFn = (acc, next) => {
acc["name"] = acc["name"] || [];
acc["name"].push(next.name);
return acc;
};

const mapFn = (next) => {
return next.name;
};
const mapFn = (next) => {
return next.name;
};

this.db.query({ tableName: databaseTables.PERSONS })
.process(reducerFn, {})
.then(result => {
console.log("Reducing.: ");
console.log(result);
})
.catch(console.error);
this.db.query({ tableName: databaseTables.PERSONS })
.process(reducerFn, {})
.then(result => {
console.log("Reducing.: ");
console.log(result);
})
.catch(console.error);

this.db.query({ tableName: databaseTables.PERSONS })
.process(mapFn)
.then(result => {
console.log("Mapping.: ");
console.log(result);
})
.catch(console.error);
}
this.db.query({ tableName: databaseTables.PERSONS })
.process(mapFn)
.then(result => {
console.log("Mapping.: ");
console.log(result);
})
.catch(console.error);
}

}
16 changes: 8 additions & 8 deletions demo/nativescript.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { NativeScriptConfig } from '@nativescript/core';
import { NativeScriptConfig } from "@nativescript/core";

export default {
id: 'org.nativescript.sqliteacces',
appPath: 'app',
appResourcesPath: 'App_Resources',
android: {
v8Flags: '--expose_gc',
markingMode: 'none'
}
id: "org.nativescript.sqliteacces",
appPath: "app",
appResourcesPath: "App_Resources",
android: {
v8Flags: "--expose_gc",
markingMode: "none"
}
} as NativeScriptConfig;
3 changes: 2 additions & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
},
"devDependencies": {
"@jsdevtools/coverage-istanbul-loader": "3.0.5",
"@nativescript/android": "8.1.1",
"@nativescript/android": "8.2.2",
"@nativescript/ios": "8.2.3",
"@nativescript/types": "~8.1.1",
"@nativescript/unit-test-runner": "~3.0.0",
"@nativescript/webpack": "~5.0.0",
"@types/karma-chai": "0.1.3",
"@types/mocha": "9.1.0",
"@typescript-eslint/eslint-plugin": "^5.19.0",
"chai": "4.3.6",
"karma": "6.3.18",
"karma-chai": "0.1.0",
Expand Down
19 changes: 0 additions & 19 deletions src/sqlite-access.android.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4826359

Please sign in to comment.