ci) add gitea actions and refresh readme (#1)
Some checks failed
Build and Push Image / docker-build-and-push (push) Failing after 2m13s
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>
This commit was merged in pull request #1.
This commit is contained in:
@@ -3,10 +3,12 @@ import { createSqliteDb } from './sqlite.js';
|
||||
import { runMigrations } from './migrations.js';
|
||||
import type { Database } from './types.js';
|
||||
|
||||
function createDb(): Database {
|
||||
const url = env.DATABASE_URL ?? 'file:trips.db';
|
||||
const isVitest = process.env.VITEST === 'true';
|
||||
|
||||
if (url.startsWith('file:') || url.endsWith('.db')) {
|
||||
function createDb(): Database {
|
||||
const url = isVitest ? ':memory:' : (env.DATABASE_URL ?? 'file:trips.db');
|
||||
|
||||
if (url === ':memory:' || url.startsWith('file:') || url.endsWith('.db')) {
|
||||
return createSqliteDb(url);
|
||||
}
|
||||
|
||||
@@ -17,7 +19,9 @@ function createDb(): Database {
|
||||
|
||||
export let db: Database = createDb();
|
||||
|
||||
runMigrations(db);
|
||||
if (!isVitest) {
|
||||
runMigrations(db);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the database singleton. For use in tests only — call this with an
|
||||
|
||||
@@ -1,23 +1,28 @@
|
||||
import BetterSqlite3 from 'better-sqlite3';
|
||||
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 BetterSqlite3(path);
|
||||
const db = new BunSqliteDatabase(path);
|
||||
|
||||
// Enable WAL mode for better concurrent read performance
|
||||
db.pragma('journal_mode = WAL');
|
||||
try {
|
||||
db.exec('PRAGMA journal_mode = WAL');
|
||||
} catch {
|
||||
// This can fail when multiple processes initialize the same DB concurrently.
|
||||
}
|
||||
|
||||
return {
|
||||
run(sql, params = []) {
|
||||
db.prepare(sql).run(params);
|
||||
db.query(sql).run(...params);
|
||||
},
|
||||
get<T = Record<string, unknown>>(sql: string, params: unknown[] = []) {
|
||||
return db.prepare(sql).get(params) as T | undefined;
|
||||
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.prepare(sql).all(params) as T[];
|
||||
return db.query(sql).all(...params) as T[];
|
||||
},
|
||||
close() {
|
||||
db.close();
|
||||
|
||||
Reference in New Issue
Block a user