Skip to content

Commit 90526f0

Browse files
committed
v0breaking: dropped eventContextKeyName option and auto-type generation
The default type did not include the schema and was impossible to override. It's better left up to the user.
1 parent 5548510 commit 90526f0

2 files changed

Lines changed: 12 additions & 21 deletions

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ Setup $postgres on event and optionally migrate the db when starting the server:
7676
import { defineNitroPlugin } from "#imports"
7777
import { migrate, postgres } from "../path/to/instance/or#postgres"
7878

79+
// here or in some global types file
80+
import { PgliteDatabase } from "drizzle-orm/pglite"
81+
import { PostgresJsDatabase } from "drizzle-orm/postgres-js"
82+
import * as schema from "~~/db/schema.js"
83+
declare module 'h3' {
84+
interface H3EventContext {
85+
${options.eventContextKeyName}: PgliteDatabase<typeof schema> | PostgresJsDatabase<typeof schema>;
86+
}
87+
}
88+
export {}
89+
90+
7991
export default defineNitroPlugin((nitroApp) => {
8092

8193
// the module auto types the $postgres key (you can change the key name with the eventContextKeyName option)

src/module.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,6 @@ declare module "@nuxt/schema" {
161161
}
162162

163163
export interface ModuleOptions extends PostgresOptions, ClientPostgresOptions {
164-
/**
165-
* Will create the types for this key on the H3Event
166-
*
167-
* @default $postgres
168-
*/
169-
eventContextKeyName: string
170164
/**
171165
* Where the postgres instance is (no extension needed), to set the #postgres alias autimatically.
172166
*
@@ -203,7 +197,6 @@ export default defineNuxtModule<ModuleOptions>({
203197
useClientDb: false,
204198
devAutoGenerateMigrations: false,
205199
autoMigrateClientDb: true,
206-
eventContextKeyName: "$postgres",
207200
aliasServerImport: "~~/server/postgres"
208201
},
209202
async setup(options, nuxt) {
@@ -310,20 +303,6 @@ export default defineNuxtModule<ModuleOptions>({
310303
nuxt.options.alias["#postgres"] = resolveAlias(options.aliasServerImport, nuxt.options.alias)
311304
}
312305

313-
addTypeTemplate({
314-
filename: "types/witchcraft-postgres.d.ts",
315-
getContents: () => `
316-
import { PgliteDatabase } from "drizzle-orm/pglite"
317-
import { PostgresJsDatabase } from "drizzle-orm/postgres-js"
318-
declare module 'h3' {
319-
interface H3EventContext {
320-
${options.eventContextKeyName}: PgliteDatabase | PostgresJsDatabase;
321-
}
322-
}
323-
export {}
324-
`
325-
})
326-
327306
nuxt.hook("vite:extendConfig", config => {
328307
// https:// pglite.dev/docs/bundler-support#vite
329308
// @ts-expect-error - same as above

0 commit comments

Comments
 (0)