Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const client = createClient({
{{/if}}
});

export const db = drizzle({ client, schema });
export const createDb = (env?: any) => drizzle({ client, schema });
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep db export available for generated consumers

This change renames the package-level export from db to createDb, but the rest of the templates still import db directly (for example auth/better-auth/server/base/src/index.ts.hbs lines 81 and 153, and examples/todo/server/drizzle/base/src/routers/todo.ts.hbs lines 4 and 45). Any generated drizzle+sqlite project that includes those flows will fail type-check/build with “no exported member db” until every consumer is migrated in the same change.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Breaking change: Renaming db to createDb breaks downstream imports.

The context snippets show that other templates (todo.ts.hbs, better-auth/server/base/src/index.ts.hbs) import db as a named import:

import { db } from "@{{projectName}}/db";

These imports will fail after this change. Either update all consuming templates to use createDb, or re-export a compatibility alias.

🔧 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 createDb() where db was used.

#!/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")}}
Expand All @@ -21,7 +21,7 @@ import * as schema from "./schema";
import { drizzle } from "drizzle-orm/d1";
import { env } from "@{{projectName}}/env/server";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Unused import: env is imported but shadowed by function parameter.

Line 22 imports env from the env package, but line 24 declares a function parameter also named env. The imported env is never used in the D1 branch.

🧹 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";
Expand All @@ -34,6 +34,6 @@ const client = createClient({
{{/if}}
});

export const db = drizzle({ client, schema });
export const createDb = (env?: any) => drizzle({ client, schema });
{{/if}}
{{/if}}