Files
emdash-blog-template/src/lib/db.ts
Kunthawat Greethong 71e05f9d2c Fix SQLite database path to match emdash init location
The emdash CLI creates the database at ./data.db relative to the
workspace root (/app/emdash/data.db), but the Astro config was
pointing to ./storage/data.db. This caused getEmDashEntry() to
return null since the database used at runtime was empty.

Change db.ts to use file:./data.db instead of file:./storage/data.db

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-04 07:33:40 +07:00

33 lines
830 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 - matches where emdash init creates the database
return sqlite({ url: "file:./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:./data.db" });
}