21258edd95
Hop-State: A_06FP5KEDBTB4A9ZT7QB498G Hop-Proposal: R_06FP5KDWMCKVVMQZT4MVZ28 Hop-Task: T_06FP5DZ7T0G45FG93PT90B8 Hop-Attempt: AT_06FP5DZ7T0PKQW99V27JCV8
20 lines
694 B
TypeScript
20 lines
694 B
TypeScript
import { mkdirSync } from 'node:fs';
|
|
import { dirname, resolve } from 'node:path';
|
|
import { drizzle } from 'drizzle-orm/tursodatabase/database';
|
|
import { relations } from './relations';
|
|
|
|
const configuredPath = process.env.DATABASE_PATH || './data/synapsis.db';
|
|
const databasePath = configuredPath === ':memory:' ? configuredPath : resolve(configuredPath);
|
|
|
|
if (databasePath !== ':memory:') {
|
|
mkdirSync(dirname(databasePath), { recursive: true });
|
|
}
|
|
|
|
export const db = drizzle(databasePath, { relations });
|
|
|
|
// Embedded Turso is always available; DATABASE_PATH only changes its location.
|
|
export const isDbAvailable = () => true;
|
|
|
|
// Export schema for use elsewhere
|
|
export * from './schema';
|