hk-planner/backend/src/db.js
jtricerolph 4abae5eda1 Initial commit: HK Planner app
Housekeeping workload and hours planning app — port of the WP hotel
housekeeping hours calculator plugin. 7-day occupancy planner with
Newbook PMS integration, staff rota, time requirements, and pickup tracking.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-02 09:24:14 +00:00

26 lines
739 B
JavaScript

import pg from 'pg'
const { Pool } = pg
export const pool = new Pool({ connectionString: process.env.DATABASE_URL })
export async function initDb() {
await pool.query(`
CREATE TABLE IF NOT EXISTS hk_config (
key TEXT PRIMARY KEY,
value JSONB NOT NULL DEFAULT 'null'::jsonb
)
`)
}
export async function getConfig(key, defaultVal = null) {
const { rows } = await pool.query('SELECT value FROM hk_config WHERE key = $1', [key])
return rows.length ? rows[0].value : defaultVal
}
export async function setConfig(key, value) {
await pool.query(
`INSERT INTO hk_config (key, value) VALUES ($1, $2::jsonb)
ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value`,
[key, JSON.stringify(value)]
)
}