-
Notifications
You must be signed in to change notification settings - Fork 424
/
Copy pathdb.js
51 lines (46 loc) · 1.46 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
const path = require('path')
const db_location = path.join(__dirname, 'gdurl.sqlite')
const db = require('better-sqlite3')(db_location)
db.pragma('journal_mode = WAL')
create_table_copied()
function create_table_copied () {
const [exists] = db.prepare('PRAGMA table_info(copied)').all()
if (exists) return
const create_table = `CREATE TABLE "copied" (
"taskid" INTEGER,
"fileid" TEXT
)`
db.prepare(create_table).run()
const create_index = `CREATE INDEX "copied_taskid" ON "copied" ("taskid");`
db.prepare(create_index).run()
}
create_table_bookmark()
function create_table_bookmark () {
const [exists] = db.prepare('PRAGMA table_info(bookmark)').all()
if (exists) return
const create_table = `CREATE TABLE "bookmark" (
"alias" TEXT,
"target" TEXT
);`
db.prepare(create_table).run()
const create_index = `CREATE UNIQUE INDEX "bookmark_alias" ON "bookmark" (
"alias"
);`
db.prepare(create_index).run()
}
create_table_hash()
function create_table_hash () {
const [exists] = db.prepare('PRAGMA table_info(hash)').all()
if (exists) return
const create_table = `CREATE TABLE "hash" (
"md5" TEXT NOT NULL,
"gid" TEXT NOT NULL UNIQUE,
"status" TEXT NOT NULL DEFAULT 'normal'
);`
db.prepare(create_table).run()
const create_index = 'CREATE INDEX "hash_md5" ON "hash" ("md5");'
db.prepare(create_index).run()
const create_index2 = 'CREATE INDEX "hash_gid" ON "hash" ("gid");'
db.prepare(create_index2).run()
}
module.exports = { db }