You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1018 B
JavaScript

/** @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,
image BLOB,
template TEXT,
name TEXT,
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 {Blob} [image]
* @property {string} [template]
* @property {string} [name]
* @property {string} [content] Stringified contents
*/