-
-
Notifications
You must be signed in to change notification settings - Fork 293
fix: avoid module-scoped DB clients in workers #964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ const client = createClient({ | |
| {{/if}} | ||
| }); | ||
|
|
||
| export const db = drizzle({ client, schema }); | ||
| export const createDb = (env?: any) => drizzle({ client, schema }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Breaking change: Renaming The context snippets show that other templates ( import { db } from "@{{projectName}}/db";These imports will fail after this change. Either update all consuming templates to use 🔧 Option: Add backward-compatible re-export (all three branches)-export const createDb = (env?: any) => drizzle({ client, schema });
+export const createDb = (env?: any) => drizzle({ client, schema });
+export const db = createDb();Or update all downstream templates to call #!/bin/bash
# Find all templates that import `db` from the db package
rg -n "import.*\bdb\b.*from.*@.*db" packages/template-generator/templates --glob '*.hbs'Also applies to: 24-24, 37-37 |
||
| {{/if}} | ||
|
|
||
| {{#if (eq runtime "workers")}} | ||
|
|
@@ -21,7 +21,7 @@ import * as schema from "./schema"; | |
| import { drizzle } from "drizzle-orm/d1"; | ||
| import { env } from "@{{projectName}}/env/server"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused import: Line 22 imports 🧹 Proposed fix: Remove unused import {{`#if` (eq dbSetup "d1")}}
import { drizzle } from "drizzle-orm/d1";
-import { env } from "@{{projectName}}/env/server";
export const createDb = (env: any) => drizzle(env.DB, { schema });Also applies to: 24-24 |
||
|
|
||
| export const db = drizzle(env.DB, { schema }); | ||
| export const createDb = (env: any) => drizzle(env.DB, { schema }); | ||
| {{else}} | ||
| import { drizzle } from "drizzle-orm/libsql"; | ||
| import { env } from "@{{projectName}}/env/server"; | ||
|
|
@@ -34,6 +34,6 @@ const client = createClient({ | |
| {{/if}} | ||
| }); | ||
|
|
||
| export const db = drizzle({ client, schema }); | ||
| export const createDb = (env?: any) => drizzle({ client, schema }); | ||
| {{/if}} | ||
| {{/if}} | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dbexport available for generated consumersThis change renames the package-level export from
dbtocreateDb, but the rest of the templates still importdbdirectly (for exampleauth/better-auth/server/base/src/index.ts.hbslines 81 and 153, andexamples/todo/server/drizzle/base/src/routers/todo.ts.hbslines 4 and 45). Any generated drizzle+sqlite project that includes those flows will fail type-check/build with “no exported memberdb” until every consumer is migrated in the same change.Useful? React with 👍 / 👎.