Files
emdash-blog-template/src/lib/db.ts
Kunthawat Greethong 557ed9e2d0 Remove mysql export that doesn't exist in patched emdash 0.9.0
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>
2026-05-03 11:37:01 +07:00

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" });
}