forked from kragen/yamemex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.js
42 lines (34 loc) · 1.38 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
function dbErrorCallback(t, error) {
console.log('SQL error %o', error);
return true;
}
function nop(){}
var db = openDatabase('pagenotes', '1.0', 'PageNotes annotation database', 0);
function sql(statement, args, cb, errorCallback) {
db.transaction(function(t) {
t.executeSql( statement
, args || []
, cb
, errorCallback || dbErrorCallback
);
});
}
sql( 'create table if not exists annotations ' +
' ( timestamp varchar ' +
' , url varchar ' +
' , annotation varchar ' +
' )'
);
sql('alter table annotations add column title varchar', [], null, nop);
sql('create unique index if not exists annotations_url on annotations (url)');
sql('drop index if exists blog');
sql('create index if not exists blog2 on annotations ( timestamp ' +
' , url' +
' , annotation' +
' , title' +
' )'
);
sql('alter table annotations add column public boolean', [], null, nop);
// This is for upgrading bookmarks created before the public column.
sql('create index if not exists puburl on annotations (public, url)');
sql('update annotations set public = 1 where public is null');