-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.js
52 lines (44 loc) · 1.3 KB
/
db.js
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
import * as SQLite from 'expo-sqlite';
const db = SQLite.openDatabase("db.db");
export const migrate = () => {
db.transaction(tx => {
tx.executeSql(
"create table if not exists list_items (id integer primary key not null, selected int, title text);");
});
}
export const getListItems = (callback) => {
db.transaction(tx => {
tx.executeSql('select * from list_items',null,(tx,items)=>{
const obj=items.rows._array
callback(obj)
})})
}
export const toggleItem = (id) => {
db.transaction(tx => {
tx.executeSql('update list_items set selected=not selected where id=?',[id])
})
}
export const deleteItem = (id) => {
db.transaction(tx => {
tx.executeSql('delete from list_items where id=?',[id])
})
}
export const selectAll = (id) => {
db.transaction(tx => {
tx.executeSql('update list_items set selected=1')
})
}
export const deselectAll = (id) => {
db.transaction(tx => {
tx.executeSql('update list_items set selected=0')
})
}
export const removeAll = () => {
db.transaction(tx => {
tx.executeSql('delete from list_items')
})
}
export const addItem = (text) => {
db.transaction(tx => {
tx.executeSql('insert into list_items(selected,title) values (1,?)',[text])})
}