From ea203c3390fd5d0d84276c6feba5dbf627d8149d Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Thu, 7 Mar 2024 07:51:02 -0500 Subject: [PATCH 1/3] fix: drizzle vs config export problem --- packages/db/src/core/consts.ts | 1 - packages/db/src/core/integration/typegen.ts | 4 +-- .../db/src/core/integration/vite-plugin-db.ts | 11 ++------ packages/db/src/runtime/config.ts | 27 ++++++++++++++++++- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/packages/db/src/core/consts.ts b/packages/db/src/core/consts.ts index bf295a2dc9a8..55e4ab0a3758 100644 --- a/packages/db/src/core/consts.ts +++ b/packages/db/src/core/consts.ts @@ -5,7 +5,6 @@ export const PACKAGE_NAME = JSON.parse( ).name; export const RUNTIME_IMPORT = JSON.stringify(`${PACKAGE_NAME}/runtime`); -export const RUNTIME_DRIZZLE_IMPORT = JSON.stringify(`${PACKAGE_NAME}/runtime/drizzle`); export const RUNTIME_CONFIG_IMPORT = JSON.stringify(`${PACKAGE_NAME}/runtime/config`); export const DB_TYPES_FILE = 'db-types.d.ts'; diff --git a/packages/db/src/core/integration/typegen.ts b/packages/db/src/core/integration/typegen.ts index 1c4834d13e1f..7c046dbfd3ad 100644 --- a/packages/db/src/core/integration/typegen.ts +++ b/packages/db/src/core/integration/typegen.ts @@ -1,6 +1,6 @@ import { existsSync } from 'node:fs'; import { mkdir, writeFile } from 'node:fs/promises'; -import { DB_TYPES_FILE, RUNTIME_DRIZZLE_IMPORT, RUNTIME_IMPORT } from '../consts.js'; +import { DB_TYPES_FILE, RUNTIME_CONFIG_IMPORT, RUNTIME_IMPORT } from '../consts.js'; import type { DBTable, DBTables } from '../types.js'; export async function typegen({ tables, root }: { tables: DBTables; root: URL }) { @@ -8,7 +8,7 @@ export async function typegen({ tables, root }: { tables: DBTables; root: URL }) declare module 'astro:db' { export const db: import(${RUNTIME_IMPORT}).SqliteDB; export const dbUrl: string; - export * from ${RUNTIME_DRIZZLE_IMPORT}; + export * from ${RUNTIME_CONFIG_IMPORT}; ${Object.entries(tables) .map(([name, collection]) => generateTableType(name, collection)) diff --git a/packages/db/src/core/integration/vite-plugin-db.ts b/packages/db/src/core/integration/vite-plugin-db.ts index 65a9fa6a03b6..ec512962d391 100644 --- a/packages/db/src/core/integration/vite-plugin-db.ts +++ b/packages/db/src/core/integration/vite-plugin-db.ts @@ -1,13 +1,7 @@ import { fileURLToPath } from 'node:url'; import { normalizePath } from 'vite'; import { SEED_DEV_FILE_NAME } from '../../runtime/queries.js'; -import { - DB_PATH, - RUNTIME_CONFIG_IMPORT, - RUNTIME_DRIZZLE_IMPORT, - RUNTIME_IMPORT, - VIRTUAL_MODULE_ID, -} from '../consts.js'; +import { DB_PATH, RUNTIME_CONFIG_IMPORT, RUNTIME_IMPORT, VIRTUAL_MODULE_ID } from '../consts.js'; import type { DBTables } from '../types.js'; import { type VitePlugin, getDbDirectoryUrl, getRemoteDatabaseUrl } from '../utils.js'; @@ -116,7 +110,6 @@ ${ : '' } -export * from ${RUNTIME_DRIZZLE_IMPORT}; export * from ${RUNTIME_CONFIG_IMPORT}; ${getStringifiedCollectionExports(tables)}`; @@ -136,7 +129,7 @@ export const db = await createRemoteDatabaseClient(${JSON.stringify( appToken // Respect runtime env for user overrides in SSR )}, import.meta.env.ASTRO_STUDIO_REMOTE_DB_URL ?? ${JSON.stringify(getRemoteDatabaseUrl())}); -export * from ${RUNTIME_DRIZZLE_IMPORT}; + export * from ${RUNTIME_CONFIG_IMPORT}; ${getStringifiedCollectionExports(tables)} diff --git a/packages/db/src/runtime/config.ts b/packages/db/src/runtime/config.ts index 5fb87e7a5c15..f208875370e9 100644 --- a/packages/db/src/runtime/config.ts +++ b/packages/db/src/runtime/config.ts @@ -45,4 +45,29 @@ export function defineDB(userConfig: DBConfigInput) { return userConfig; } -export { sql, NOW, TRUE, FALSE } from './index.js'; +export { NOW, TRUE, FALSE } from './index.js'; + +export { + sql, + eq, + gt, + gte, + lt, + lte, + ne, + isNull, + isNotNull, + inArray, + notInArray, + exists, + notExists, + between, + notBetween, + like, + notIlike, + not, + asc, + desc, + and, + or, +} from 'drizzle-orm'; From 4af1c47891a57c14707be94929724c564fb40a13 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Thu, 7 Mar 2024 07:51:17 -0500 Subject: [PATCH 2/3] chore: remove drizzle runtime export --- packages/db/package.json | 7 ------- 1 file changed, 7 deletions(-) diff --git a/packages/db/package.json b/packages/db/package.json index 047843fc312a..724c923187a9 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -20,10 +20,6 @@ "types": "./dist/runtime/index.d.ts", "import": "./dist/runtime/index.js" }, - "./runtime/drizzle": { - "types": "./dist/runtime/drizzle.d.ts", - "import": "./dist/runtime/drizzle.js" - }, "./runtime/config": { "types": "./dist/runtime/config.d.ts", "import": "./dist/runtime/config.js" @@ -41,9 +37,6 @@ "runtime": [ "./dist/runtime/index.d.ts" ], - "runtime/drizzle": [ - "./dist/runtime/drizzle.d.ts" - ], "runtime/config": [ "./dist/runtime/config.d.ts" ] From 2e327da42551f9992e44fc732bfcd4b29177600d Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Thu, 7 Mar 2024 08:02:51 -0500 Subject: [PATCH 3/3] chore: changeset --- .changeset/chilly-cherries-appear.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/chilly-cherries-appear.md diff --git a/.changeset/chilly-cherries-appear.md b/.changeset/chilly-cherries-appear.md new file mode 100644 index 000000000000..80fc9b123df6 --- /dev/null +++ b/.changeset/chilly-cherries-appear.md @@ -0,0 +1,5 @@ +--- +"@astrojs/db": patch +--- + +Fix runtime export error when building with the node adapter