import { sqlite, postgres } from "emdash/db"; /** * Database configuration from environment variables. * * Supports: * - SQLite: DATABASE_URL=file:./storage/data.db * - PostgreSQL: DATABASE_URL=postgresql://user:pass@host:5432/db * - MySQL: DATABASE_URL=mysql://user:pass@host:3306/db */ export function getDatabaseConfig() { const url = process.env.DATABASE_URL; if (!url) { // Default to SQLite return sqlite({ url: "file:./storage/data.db" }); } if (url.startsWith("file:")) { // SQLite return sqlite({ url: url }); } if (url.startsWith("postgresql:")) { // PostgreSQL return postgres({ connectionString: url }); } // Fallback to SQLite console.warn(`Unknown DATABASE_URL protocol, falling back to SQLite`); return sqlite({ url: "file:./storage/data.db" }); }