Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for BigInt #14

Merged
merged 4 commits into from Aug 13, 2022
Merged

Conversation

carloschida
Copy link
Contributor

Description

Currently Prisma's BigInt is not parsed. For instance if we extend the Post model with likes:

model Post {
  id        Int      @id @default(autoincrement())
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  title     String
  content   String?
  published Boolean  @default(false)
  viewCount Int      @default(0)
  author    User?    @relation(fields: [authorId], references: [id])
  authorId  Int?
  likes     BigInt
}

One of the results is:

const Schema: z.ZodType<Prisma.PostCreateInput> = z
  .object({
    createdAt: z.bigint().optional(),
    updatedAt: z.bigint().optional(),
    title: z.string(),
    content: z.union([z.string(), z.bigint()]).optional().nullable(),
    published: z.bigint().optional(),
    viewCount: z.number().optional(),
    author: z.bigint().optional(),
  })
  .strict();

export const PostCreateInputObjectSchema = Schema;

With the proposed fix, the schema now includes likes:

const Schema: z.ZodType<Prisma.PostCreateInput> = z
  .object({
   // ...
    author: z.bigint().optional(),
    likes: z.bigint(),
  })
  .strict();

To test the fix, simply run npm run gen-example and inspect the file prisma/generated/schemas/objects/PostCreateInput.schema.ts.

@omar-dulaimi omar-dulaimi self-assigned this Aug 13, 2022
@omar-dulaimi omar-dulaimi added the enhancement New feature or request label Aug 13, 2022
@omar-dulaimi
Copy link
Owner

Thank you for the contribution @carloschida
LGTM!

@omar-dulaimi omar-dulaimi merged commit db35596 into omar-dulaimi:master Aug 13, 2022
@omar-dulaimi
Copy link
Owner

@eglove
Copy link

eglove commented Aug 13, 2022

tsc postinstall causes fail

R4hNciG

@omar-dulaimi
Copy link
Owner

@eglove Please try again with 0.5.1

Also, make sure to star this project if you find it useful.

BitPhoenix pushed a commit to BitPhoenix/prisma-zod-generator that referenced this pull request Oct 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants