|
|
|
|
@ -28,7 +28,14 @@ function applyDefaultPragmas(instance: any): void {
|
|
|
|
|
* - En Node (Vite dev SSR): better-sqlite3
|
|
|
|
|
*/
|
|
|
|
|
async function importSqliteDatabase(): Promise<any> {
|
|
|
|
|
// En desarrollo, el alias de Vite resolverá 'bun:sqlite' -> 'better-sqlite3'
|
|
|
|
|
// En desarrollo (Vite SSR), cargar better-sqlite3 vía require de Node para mantener el contexto CJS
|
|
|
|
|
if (import.meta.env.DEV) {
|
|
|
|
|
const modModule: any = await import('node:module');
|
|
|
|
|
const require = modModule.createRequire(import.meta.url);
|
|
|
|
|
const mod = require('better-sqlite3');
|
|
|
|
|
return (mod as any).default || (mod as any).Database || mod;
|
|
|
|
|
}
|
|
|
|
|
// En producción (Bun en runtime), usar bun:sqlite nativo
|
|
|
|
|
const mod: any = await import('bun:sqlite');
|
|
|
|
|
return (mod as any).Database || (mod as any).default || mod;
|
|
|
|
|
}
|
|
|
|
|
|