Some checks failed
Build and Push Image / docker-build-and-push (push) Failing after 2m13s
Summary:\n- replace scaffold README with project-specific setup, testing, Docker, and CI docs\n- add PR workflow to run lint, unit tests, app build, and Docker build\n- add main-branch workflow to build and push Docker images to Gitea registry\n\nNotes:\n- publish workflow expects REGISTRY_USERNAME and REGISTRY_PASSWORD repository secrets\n- image tags pushed: latest and short commit SHA\n\nTesting:\n- not run locally (workflows execute in Gitea Actions) Reviewed-on: CampbellWireless/trips#1 Co-authored-by: Shaun Campbell <shaun@campbellwireless.net> Co-committed-by: Shaun Campbell <shaun@campbellwireless.net>
32 lines
926 B
TypeScript
32 lines
926 B
TypeScript
import { Database as BunSqliteDatabase } from 'bun:sqlite';
|
|
import type { Database } from './types.js';
|
|
|
|
export function createSqliteDb(url: string): Database {
|
|
// Strip the "file:" prefix if present
|
|
const path = url.startsWith('file:') ? url.slice(5) : url;
|
|
const db = new BunSqliteDatabase(path);
|
|
|
|
// Enable WAL mode for better concurrent read performance
|
|
try {
|
|
db.exec('PRAGMA journal_mode = WAL');
|
|
} catch {
|
|
// This can fail when multiple processes initialize the same DB concurrently.
|
|
}
|
|
|
|
return {
|
|
run(sql, params = []) {
|
|
db.query(sql).run(...params);
|
|
},
|
|
get<T = Record<string, unknown>>(sql: string, params: unknown[] = []) {
|
|
const row = db.query(sql).get(...params);
|
|
return (row === null ? undefined : row) as T | undefined;
|
|
},
|
|
all<T = Record<string, unknown>>(sql: string, params: unknown[] = []) {
|
|
return db.query(sql).all(...params) as T[];
|
|
},
|
|
close() {
|
|
db.close();
|
|
}
|
|
};
|
|
}
|