-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba6c812
commit 4826359
Showing
11 changed files
with
83 additions
and
159 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.