bigly-chat/db.js

28 lines
946 B
JavaScript
Raw Normal View History

2024-09-07 18:12:58 -04:00
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);`);
2024-09-19 05:58:01 -04:00
await db.run(`CREATE TABLE IF NOT EXISTS video (id TEXT, title TEXT, desc TEXT, username TEXT, date REAL);`);
2024-09-22 03:49:36 -04:00
await db.run('CREATE TABLE IF NOT EXISTS comment (username TEXT, targetType TEXT, targetId TEXT, date REAL, content TEXT, id TEXT);');
2024-09-19 05:44:24 -04:00
2024-09-22 10:49:47 -04:00
await db.run('CREATE TABLE IF NOT EXISTS follow (username TEXT, target TEXT);');
2024-09-27 03:59:23 -04:00
await db.run(`CREATE TABLE IF NOT EXISTS user (username TEXT, bio TEXT);`);
2024-10-28 04:54:58 -04:00
await db.run(`CREATE TABLE IF NOT EXISTS captcha (key TEXT, solution TEXT);`);
2024-09-27 03:59:23 -04:00
2024-09-07 18:12:58 -04:00
return db;
}
export default initDb;