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:
parent
93100c6a7c
commit
7536e18a68
3 changed files with 16 additions and 9 deletions
|
@ -11,7 +11,8 @@ export const DB_TYPES_FILE = 'db-types.d.ts';
|
||||||
|
|
||||||
export const VIRTUAL_MODULE_ID = 'astro:db';
|
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) {
|
export function getLocalDbUrl(root: URL) {
|
||||||
return new URL('.astro/content.db', root);
|
return new URL(DB_PATH, root);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,11 @@ export function integration(): AstroIntegration {
|
||||||
logger.error(appTokenError);
|
logger.error(appTokenError);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
dbPlugin = vitePluginDb({ connectToStudio: true, collections, appToken });
|
dbPlugin = vitePluginDb({
|
||||||
|
connectToStudio: true,
|
||||||
|
collections,
|
||||||
|
appToken
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
const dbUrl = getLocalDbUrl(config.root);
|
const dbUrl = getLocalDbUrl(config.root);
|
||||||
if (existsSync(dbUrl)) {
|
if (existsSync(dbUrl)) {
|
||||||
|
|
|
@ -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 { DBCollections } from './types.js';
|
||||||
import type { VitePlugin } from './utils.js';
|
import type { VitePlugin } from './utils.js';
|
||||||
|
|
||||||
|
@ -46,11 +46,13 @@ export function getVirtualModContents({
|
||||||
return `
|
return `
|
||||||
import { collectionToTable, createLocalDatabaseClient } from ${INTERNAL_MOD_IMPORT};
|
import { collectionToTable, createLocalDatabaseClient } from ${INTERNAL_MOD_IMPORT};
|
||||||
|
|
||||||
export const db = await createLocalDatabaseClient(${JSON.stringify({
|
const params = ${JSON.stringify({
|
||||||
collections,
|
collections,
|
||||||
dbUrl,
|
seeding: false,
|
||||||
seeding: false,
|
})};
|
||||||
})});
|
|
||||||
|
params.dbUrl = new URL(${JSON.stringify(DB_PATH)}, 'file://' + process.cwd() + '/');
|
||||||
|
export const db = await createLocalDatabaseClient(params);
|
||||||
|
|
||||||
export * from ${DRIZZLE_MOD_IMPORT};
|
export * from ${DRIZZLE_MOD_IMPORT};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue