-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.js
More file actions
27 lines (22 loc) · 749 Bytes
/
Copy pathdatabase.js
File metadata and controls
27 lines (22 loc) · 749 Bytes
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
const Database = require('better-sqlite3');
const path = require('path');
const db = new Database(path.join(__dirname, 'filehost.db'));
db.pragma('journal_mode = WAL');
db.pragma('foreign_keys = ON');
db.exec(`
CREATE TABLE IF NOT EXISTS folders (
id TEXT PRIMARY KEY,
name TEXT NOT NULL,
parent_id TEXT,
created_at TEXT DEFAULT (datetime('now')),
FOREIGN KEY (parent_id) REFERENCES folders(id) ON DELETE SET NULL
)
`);
const columns = db.prepare("PRAGMA table_info(files)").all().map(c => c.name);
if (!columns.includes('folder_id')) {
db.exec(`ALTER TABLE files ADD COLUMN folder_id TEXT`);
}
if (!columns.includes('custom_name')) {
db.exec(`ALTER TABLE files ADD COLUMN custom_name TEXT`);
}
module.exports = db;