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.

Revisions

  1. lawrencecchen revised this gist Apr 2, 2023. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion db.ts
    Original file line number Diff line number Diff line change
    @@ -11,6 +11,8 @@ export type Database = {

    export const db = new Kysely<Database>({
    dialect: new PlanetScaleDialect({
    url: process.env.DATABASE_URL,
    host: process.env.DATABASE_HOST,
    username: process.env.DATABASE_USERNAME,
    password: process.env.DATABASE_PASSWORD,
    }),
    });
  2. lawrencecchen revised this gist Apr 2, 2023. No changes.
  3. lawrencecchen revised this gist Apr 2, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion db.ts
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    import { Kysely } from "kysely";
    import { PlanetScaleDialect } from "kysely-planetscale";
    import { z } from "zod";
    import { type z } from "zod";

    import * as Models from "./prisma/generated/zod/modelSchema";

  4. lawrencecchen created this gist Apr 2, 2023.
    16 changes: 16 additions & 0 deletions db.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    import { Kysely } from "kysely";
    import { PlanetScaleDialect } from "kysely-planetscale";
    import { 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({
    url: process.env.DATABASE_URL,
    }),
    });
    4 changes: 4 additions & 0 deletions schema.prisma
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    generator zod {
    provider = "zod-prisma-types"
    useMultipleFiles = true
    }