login and register logic

This commit is contained in:
biglyderv 2025-02-25 19:47:28 -05:00
parent a2f8452eec
commit 8d0c02e27e
Signed by: biglyderv
GPG key ID: 0E2EB0B4CD7397B5
15 changed files with 496 additions and 106 deletions

28
db.js Normal file
View file

@ -0,0 +1,28 @@
import sqlite3 from 'sqlite3'
import { open } from 'sqlite'
let db;
const sql = `CREATE TABLE IF NOT EXISTS auth (username TEXT, password TEXT);
CREATE TABLE IF NOT EXISTS token (username TEXT, token TEXT);
CREATE TABLE IF NOT EXISTS feeder (parentType TEXT, parentId TEXT, childType text, childId TEXT, sortId REAL);
CREATE TABLE IF NOT EXISTS comment (username TEXT, date REAL, content TEXT, id TEXT);`
async function initDb() {
if (db) return db;
db = await open({
filename: `${process.cwd()}/db/main.db`,
driver: sqlite3.Database
});
let sqlCmds = sql.split('\n');
for (let cmd of sqlCmds) {
await db.run(cmd);
}
return db;
}
export { initDb };