Files
Kakubovna/app/handlers/sqliteHandler.js
2023-06-07 00:14:44 +02:00

44 lines
1.4 KiB
JavaScript

module.exports = {
SqliteHandler: class SqliteHandler {
constructor(path) {
this.loaded = false;
this.path = path;
this.db = require('better-sqlite3')(this.path);
this.db.prepare(`CREATE TABLE IF NOT EXISTS "user" (
"id" INTEGER NOT NULL UNIQUE,
"name" TEXT NOT NULL UNIQUE,
"password" TEXT NOT NULL,
"email" INTEGER,
"admin" INTEGER,
PRIMARY KEY("id" AUTOINCREMENT)
)`).run();
this.db.prepare(`CREATE TABLE IF NOT EXISTS "upload" (
"id" INTEGER NOT NULL UNIQUE,
"hashsalt" TEXT NOT NULL UNIQUE,
"adminhash" TEXT NOT NULL UNIQUE,
"desc" TEXT,
"password" TEXT,
"owner_id" INTEGER,
"upload_unix" INTEGER,
PRIMARY KEY("id" AUTOINCREMENT),
FOREIGN KEY("owner_id") REFERENCES "user"("id")
)`).run();
this.db.prepare(`CREATE TABLE IF NOT EXISTS "file" (
"id" INTEGER NOT NULL UNIQUE,
"filename" TEXT NOT NULL,
"upload_id" INTEGER NOT NULL,
"state" INTEGER NOT NULL,
PRIMARY KEY("id" AUTOINCREMENT),
FOREIGN KEY("upload_id") REFERENCES "upload"("id")
)`).run();
}
getDatabaseObj() {
return this.db;
}
}
}