Last active
April 2, 2023 10:09
-
-
Save lawrencecchen/9f3ea8e05ba1ae321da986cd1330c930 to your computer and use it in GitHub Desktop.
Kysely + Prisma + zod-prisma-types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Kysely } from "kysely"; | |
import { PlanetScaleDialect } from "kysely-planetscale"; | |
import { type z } from "zod"; | |
import * as Models from "./prisma/generated/zod/modelSchema"; | |
type RemoveSchema<S extends string> = S extends `${infer Prefix}Schema` ? Prefix : S; | |
export type Database = { | |
[K in keyof typeof Models as RemoveSchema<K>]: z.infer<(typeof Models)[K]>; | |
}; | |
export const db = new Kysely<Database>({ | |
dialect: new PlanetScaleDialect({ | |
host: process.env.DATABASE_HOST, | |
username: process.env.DATABASE_USERNAME, | |
password: process.env.DATABASE_PASSWORD, | |
}), | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
generator zod { | |
provider = "zod-prisma-types" | |
useMultipleFiles = true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment