Reconcile validated Turso runtime fix with republished main history

Hop-State: A_06FP6A2CG8PVBRDVQ5WGCN0
Hop-Proposal: R_06FP6A0YW23RY0N7Z5M8DW0
Hop-Task: T_06FP67JVF4BHPYKKC37XKQ8
Hop-Attempt: AT_06FP69RZ96ZMNF9Y5S02MT0
This commit is contained in:
2026-07-14 17:23:33 -07:00
committed by Hop
20 changed files with 65 additions and 41 deletions
+19 -1
View File
@@ -10,7 +10,25 @@ if (databasePath !== ':memory:') {
mkdirSync(dirname(databasePath), { recursive: true });
}
export const db = drizzle(databasePath, { relations });
const createDb = () => drizzle(databasePath, { relations });
type SynapsisDatabase = ReturnType<typeof createDb>;
const globalForDb = globalThis as typeof globalThis & {
synapsisDb?: SynapsisDatabase;
};
export const db = globalForDb.synapsisDb ?? createDb();
globalForDb.synapsisDb = db;
export async function closeDb(): Promise<void> {
if (!globalForDb.synapsisDb) {
return;
}
await globalForDb.synapsisDb.$client.close();
delete globalForDb.synapsisDb;
}
// Embedded Turso is always available; DATABASE_PATH only changes its location.
export const isDbAvailable = () => true;