0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-06 22:10:10 -05:00

Grab the dbUrl from the environment

This commit is contained in:
Matthew Phillips 2024-01-26 14:17:26 -05:00
parent 93100c6a7c
commit 7536e18a68
3 changed files with 16 additions and 9 deletions

View file

@ -11,7 +11,8 @@ export const DB_TYPES_FILE = 'db-types.d.ts';
export const VIRTUAL_MODULE_ID = 'astro:db';
// TODO: copy DB to build for serverless
export const DB_PATH = '.astro/content.db';
export function getLocalDbUrl(root: URL) {
return new URL('.astro/content.db', root);
return new URL(DB_PATH, root);
}

View file

@ -41,7 +41,11 @@ export function integration(): AstroIntegration {
logger.error(appTokenError);
process.exit(0);
}
dbPlugin = vitePluginDb({ connectToStudio: true, collections, appToken });
dbPlugin = vitePluginDb({
connectToStudio: true,
collections,
appToken
});
} else {
const dbUrl = getLocalDbUrl(config.root);
if (existsSync(dbUrl)) {

View file

@ -1,4 +1,4 @@
import { DRIZZLE_MOD_IMPORT, INTERNAL_MOD_IMPORT, VIRTUAL_MODULE_ID } from './consts.js';
import { DRIZZLE_MOD_IMPORT, INTERNAL_MOD_IMPORT, VIRTUAL_MODULE_ID, DB_PATH } from './consts.js';
import type { DBCollections } from './types.js';
import type { VitePlugin } from './utils.js';
@ -46,11 +46,13 @@ export function getVirtualModContents({
return `
import { collectionToTable, createLocalDatabaseClient } from ${INTERNAL_MOD_IMPORT};
export const db = await createLocalDatabaseClient(${JSON.stringify({
collections,
dbUrl,
seeding: false,
})});
const params = ${JSON.stringify({
collections,
seeding: false,
})};
params.dbUrl = new URL(${JSON.stringify(DB_PATH)}, 'file://' + process.cwd() + '/');
export const db = await createLocalDatabaseClient(params);
export * from ${DRIZZLE_MOD_IMPORT};