forked from bolav/fuse-sqlite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModel.ts
More file actions
53 lines (47 loc) · 1.43 KB
/
Model.ts
File metadata and controls
53 lines (47 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import sqlite from "SQLite";
export default class Model {
result = "";
insert_id = "";
select_id = "";
prepare_id = "";
db = sqlite.openFromBundle("bundle.sqlite");
init_db() {
this.db.execute("create table if not exists ids (id integer primary key)");
}
insert_value() {
try {
this.db.execute("insert into ids values (?)", this.insert_id);
this.result = "Insert successful";
}
catch (e) {
this.result = "Error inserting " + e;
}
}
select_values() {
let r = "";
if (this.select_id != "") {
console.log("SELECT * WHERE id = " + this.select_id);
r = this.db.query("select * from ids WHERE id = ?", this.select_id);
}
else {
console.log("select * from ids");
r = this.db.query("select * from ids");
}
this.result = JSON.stringify(r);
console.log(JSON.stringify(r));
}
prepare_values() {
let r = "";
if (this.prepare_id != "") {
const stmnt = this.db.prepare("select * from ids WHERE id = ?")
r = stmnt.execute(this.prepare_id);
}
else {
console.log("select * from ids");
const stmnt = this.db.prepare("select * from ids");
r = stmnt.execute();
}
this.result = JSON.stringify(r);
console.log(JSON.stringify(r));
}
}