forked from passport/todos-express-webauthn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
47 lines (40 loc) · 1.14 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
var sqlite3 = require('sqlite3');
var mkdirp = require('mkdirp');
var path = require('path');
var fs = require('fs');
// Set the database directory
const dbDir = '/tmp';
const dbPath = path.join(dbDir, 'todos.db');
const originalDbDir = './var/db';
if (fs.existsSync(originalDbDir)) {
fs.readdirSync(originalDbDir).forEach(file => {
const sourcePath = path.join(originalDbDir, file);
const destPath = path.join('/tmp', file);
fs.copyFileSync(sourcePath, destPath);
});
}
// Open the SQLite database
var db = new sqlite3.Database(dbPath);
db.serialize(function () {
db.run("CREATE TABLE IF NOT EXISTS users ( \
id INTEGER PRIMARY KEY, \
username TEXT UNIQUE, \
hashed_password BLOB, \
salt BLOB, \
name TEXT, \
handle BLOB UNIQUE \
)");
db.run("CREATE TABLE IF NOT EXISTS public_key_credentials ( \
id INTEGER PRIMARY KEY, \
user_id INTEGER NOT NULL, \
external_id TEXT UNIQUE, \
public_key TEXT \
)");
db.run("CREATE TABLE IF NOT EXISTS todos ( \
id INTEGER PRIMARY KEY, \
owner_id INTEGER NOT NULL, \
title TEXT NOT NULL, \
completed INTEGER \
)");
});
module.exports = db;