The blog template's db.ts imported 'mysql' from 'emdash/db' but the patched source only exports sqlite, libsql, and postgres adapters. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
33 lines
797 B
TypeScript
33 lines
797 B
TypeScript
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" });
|
|
}
|