Initial commit: Sistema de Gestión Hospitalaria

This commit is contained in:
Santiago Lavaise
2026-04-12 20:52:43 -03:00
commit 78577ec922
93 changed files with 24674 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
import sqlite3 from 'sqlite3';
import { open } from 'sqlite';
import { dirname } from 'path';
import { fileURLToPath } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));
const DB_PATH = __dirname + '/data/hospital.db';
export async function openDb() {
const db = await open({
filename: DB_PATH,
driver: sqlite3.Database,
});
await db.exec(`
CREATE TABLE IF NOT EXISTS kv (
key TEXT PRIMARY KEY,
value TEXT
);
`);
return db;
}
export async function getValue(key) {
const db = await openDb();
const row = await db.get('SELECT value FROM kv WHERE key = ?', key);
await db.close();
return row?.value ?? null;
}
export async function setValue(key, value) {
const db = await openDb();
await db.run('INSERT INTO kv (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value=excluded.value', key, value);
await db.close();
}