the hourly rate is not being saved

This commit is contained in:
Leon Serfaty G
2025-07-17 11:21:35 +00:00
parent 5f38178a60
commit 6a1d37bdc7
5 changed files with 139 additions and 5 deletions
+26
View File
@@ -0,0 +1,26 @@
'use server';
import db from '@/lib/db';
export async function getSetting(key: string): Promise<string | null> {
try {
const stmt = db.prepare('SELECT value FROM settings WHERE key = ?');
const result = stmt.get(key) as { value: string } | undefined;
return result?.value ?? null;
} catch (error) {
console.error(`Failed to get setting "${key}":`, error);
return null;
}
}
export async function setSetting(key: string, value: string): Promise<void> {
try {
const stmt = db.prepare(
'INSERT INTO settings (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value'
);
stmt.run(key, value);
} catch (error) {
console.error(`Failed to set setting "${key}":`, error);
throw new Error(`Could not update setting for ${key}`);
}
}
+9 -1
View File
@@ -3,7 +3,7 @@ import Database from 'better-sqlite3';
// Use a file-based database in development
const db = new Database('local.db');
// Create the users table if it doesn't exist
// Create the tables if they don't exist
db.exec(`
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -13,4 +13,12 @@ db.exec(`
)
`);
db.exec(`
CREATE TABLE IF NOT EXISTS settings (
key TEXT PRIMARY KEY,
value TEXT
)
`);
export default db;