Skip to content

Instantly share code, notes, and snippets.

@lawrencecchen
Last active April 2, 2023 10:09
Show Gist options
  • Save lawrencecchen/9f3ea8e05ba1ae321da986cd1330c930 to your computer and use it in GitHub Desktop.
Save lawrencecchen/9f3ea8e05ba1ae321da986cd1330c930 to your computer and use it in GitHub Desktop.
Kysely + Prisma + zod-prisma-types
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,
}),
});
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