omar-dulaimi / prisma-class-validator-generator

Prisma 2+ generator to emit typescript models of your database with class validator
MIT License
65 stars 11 forks source link

Bytes type is not translated into Buffer type - Type/Import Error #16

Closed austenstrine closed 2 months ago

austenstrine commented 2 months ago

Bug description

When adding a Bytes field into a schema.prisma table, the resulting generated class sets the property as type Bytes, which is not a typescript type. This throws a type error. It should be Buffer instead.

How to reproduce

Add a Bytes type into the schema.prisma

Run npx prisma generate

Expected behavior

I expected the generator to convert Bytes into the Buffer type.

Prisma information

generator client { provider = "prisma-client-js" engineType = "binary" binaryTargets = ["native", "linux-musl-arm64-openssl-3.0.x"] previewFeatures = ["fullTextSearch"] }

datasource db { provider = "postgresql" url = env("DATABASE_URL") }

generator class_validator { provider = "prisma-class-validator-generator" }

model FileUpload { id Int @unique @id @default(autoincrement()) businessId Int userId Int? email String? schema Json? lineItemCount Int pdfName String? pdfData Bytes? @db.ByteA pdfUri String? spreadsheetName String? spreadsheetData Bytes? @db.ByteA spreadsheetUri String? approved Boolean @default(false) errors String[] attempts Int @default(0) created DateTime @default(now()) updated DateTime @updatedAt }

Environment & setup

OS: Debian GNU/Linux 11 (bullseye)

DB: psql (PostgreSQL) 13.13 (Debian 13.13-0+deb11u1)

Node: v18.19.0

Prisma Version

prisma : 4.16.2 @prisma/client : 4.16.2 Current platform : debian-openssl-1.1.x Query Engine (Node-API) : libquery-engine 4bc8b6e1b66cb932731fb1bdbbc550d1e010de81 (at node_modules/@prisma/engines/libquery_engine-debian-openssl-1.1.x.so.node) Migration Engine : migration-engine-cli 4bc8b6e1b66cb932731fb1bdbbc550d1e010de81 (at node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x) Format Wasm : @prisma/prisma-fmt-wasm 4.16.1-1.4bc8b6e1b66cb932731fb1bdbbc550d1e010de81 Default Engines Hash : 4bc8b6e1b66cb932731fb1bdbbc550d1e010de81 Studio : 0.484.0 Preview Features : fullTextSearch

austenstrine commented 2 months ago

This PR fixes the issue: https://github.com/omar-dulaimi/prisma-class-validator-generator/pull/15

austenstrine commented 2 months ago

Until such a time as this package approves the PR that adds support for Bytes (as Buffer), feel free to link this "build" branch directly in your projects. It's literally just a compiled version of the PR:

With yarn: yarn remove prisma-class-validator-generator yarn add prisma-class-validator-generator@https://github.com/austenstrine/prisma-class-validator-generator.git#build

With npm: npm uninstall prisma-class-validator-generator npm install austenstrine/prisma-class-validator-generator.git#build

Obviously not as good as the PR just getting merged, but better than waiting if you're in a pinch and need a solution "now" like I do.

omar-dulaimi commented 2 months ago

Hey @austenstrine Thanks for the PR. will merge it now and release

omar-dulaimi commented 2 months ago

Released, check: https://github.com/omar-dulaimi/prisma-class-validator-generator/releases/tag/0.2.1

austenstrine commented 2 months ago

Thank you for the quick response, sir.

omar-dulaimi commented 2 months ago

My pleasure @austenstrine If you can, please consider supporting me :)