28 lines
No EOL
946 B
JavaScript
28 lines
No EOL
946 B
JavaScript
import sqlite3 from 'sqlite3'
|
|
import { open } from 'sqlite'
|
|
|
|
let db;
|
|
|
|
async function initDb() {
|
|
if (db) return db;
|
|
|
|
db = await open({
|
|
filename: `${process.cwd()}/db/main.db`,
|
|
driver: sqlite3.Database
|
|
});
|
|
|
|
await db.run(`CREATE TABLE IF NOT EXISTS auth (username TEXT, password TEXT);`);
|
|
await db.run(`CREATE TABLE IF NOT EXISTS token (username TEXT, token TEXT);`);
|
|
|
|
await db.run(`CREATE TABLE IF NOT EXISTS video (id TEXT, title TEXT, desc TEXT, username TEXT, date REAL);`);
|
|
await db.run('CREATE TABLE IF NOT EXISTS comment (username TEXT, targetType TEXT, targetId TEXT, date REAL, content TEXT, id TEXT);');
|
|
|
|
await db.run('CREATE TABLE IF NOT EXISTS follow (username TEXT, target TEXT);');
|
|
|
|
await db.run(`CREATE TABLE IF NOT EXISTS user (username TEXT, bio TEXT);`);
|
|
await db.run(`CREATE TABLE IF NOT EXISTS captcha (key TEXT, solution TEXT);`);
|
|
|
|
return db;
|
|
}
|
|
|
|
export default initDb; |