/** @typedef {typeof import('better-sqlite3')} better-sqlite3 */
import Database from 'better-sqlite3';

export const db = new Database('./carteles_dev.sqlite', { verbose: console.log })
db.pragma("journal_mode = WAL");
db.pragma("synchronous = normal");
db.pragma("temp_store = memory");

const createUserTable = db.prepare(`CREATE TABLE IF NOT EXISTS Users (
  email TEXT PRIMARY KEY UNIQUE NOT NULL,
  password TEXT,
  isAdmin INTEGER
  );`);

const createPostersTable = db.prepare(`CREATE TABLE IF NOT EXISTS Posters (
  id INTEGER PRIMARY KEY UNIQUE NOT NULL,
  image BLOB,
  template TEXT,
  name TEXT,
  content TEXT
);`);

createUserTable.run();
createPostersTable.run();
