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

export const db = new Database('./src/lib/db/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,
  createdAt TEXT NOT NULL,
  image BLOB NOT NULL,
  content TEXT
);`);

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

/**
* @typedef {Object} User
* @property {string} [email]
* @property {string} [password]
* @property {boolean} [isAdmin]
*/

/**
* @typedef {Object} Poster
* @property {number} [id]
* @property {string} [createdAt] Date
* @property {Blob} [image]
* @property {string} [content] Stringified contents
*/
