From 68e2949feef796993189f4f1a568659608e564ae Mon Sep 17 00:00:00 2001 From: Seven Du Date: Sun, 24 Mar 2024 23:43:42 +0800 Subject: [PATCH 1/2] fix(generator): `Json` type error not found (not converted to PrismaJson) --- .gitignore | 1 + bin/src/generate_delegate.dart | 5 ++--- bin/src/generate_type.dart | 12 +++++----- lib/src/runtime/prisma_json.dart | 1 + prisma/schema.prisma | 38 +++++--------------------------- 5 files changed, 15 insertions(+), 42 deletions(-) diff --git a/.gitignore b/.gitignore index 774f6ad9..c834a940 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ pubspec.lock example/prisma/* !example/prisma/schema.prisma prisma-query-* +prisma/.env* # Prisma Engine (Rust) target/ diff --git a/bin/src/generate_delegate.dart b/bin/src/generate_delegate.dart index bc95b5b7..e1303e40 100644 --- a/bin/src/generate_delegate.dart +++ b/bin/src/generate_delegate.dart @@ -100,9 +100,8 @@ extension on Generator { } Expression generateFactory(dmmf.OutputField field) { - final serialize = refer(field.outputType.type.className) - .namespace(field.outputType.namespace) - .property('fromJson'); + final serialize = + generateType(field.outputType, isList: false).property('fromJson'); final orThrow = field.name.endsWith('OrThrow'); if (field.outputType.isList) { diff --git a/bin/src/generate_type.dart b/bin/src/generate_type.dart index 7e2551d1..1696ab6b 100644 --- a/bin/src/generate_type.dart +++ b/bin/src/generate_type.dart @@ -10,17 +10,17 @@ import 'utils/reference.dart'; import 'utils/scalars.dart'; extension GenerateType on Generator { - Reference generateType(dmmf.TypeReference type) { + Reference generateType(dmmf.TypeReference type, {bool? isList}) { return switch (type.location) { dmmf.TypeLocation.inputObjectTypes => - generateInput(type.type, type.namespace, type.isList), + generateInput(type.type, type.namespace, isList ?? type.isList), dmmf.TypeLocation.outputObjectTypes => - generateOutput(type.type, type.namespace, type.isList), + generateOutput(type.type, type.namespace, isList ?? type.isList), dmmf.TypeLocation.enumTypes => - generateEnum(type.type, type.namespace, type.isList), + generateEnum(type.type, type.namespace, isList ?? type.isList), dmmf.TypeLocation.fieldRefTypes => - generateFieldRef(type.type).list(type.isList), - _ => generateScalar(type.type, type.isList), + generateFieldRef(type.type).list(isList ?? type.isList), + _ => generateScalar(type.type, isList ?? type.isList), }; } } diff --git a/lib/src/runtime/prisma_json.dart b/lib/src/runtime/prisma_json.dart index d6a04d28..ca801a9d 100644 --- a/lib/src/runtime/prisma_json.dart +++ b/lib/src/runtime/prisma_json.dart @@ -4,6 +4,7 @@ class PrismaJson implements JsonConvertible { final Object value; const PrismaJson(this.value); + const PrismaJson.fromJson(this.value); @override Object toJson() => value; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index ca95470f..8107ec6d 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -6,41 +6,13 @@ generator dart_client { output = "dart" } -generator js_client { - provider = "prisma-client-js" -} - -generator dmmf { - provider = "dart run tool/dmmf_generator.dart" -} - datasource db { - provider = "mysql" - url = "mysql://seven@localhost:5432/prisma-dart" -} - -enum Role { - user - owner + provider = "mongodb" + url = env("DATABASE_URL") } model User { - id Int @id @default(autoincrement()) - name String - role Role @default(user) - price Decimal - size BigInt - bytes Bytes - json Json? - age Int? - count Float - createdAt DateTime @default(now()) - posts Post[] -} - -model Post { - id String @id @default(cuid()) - title String - author User @relation(fields: [userId], references: [id]) - userId Int + id String @id @default(auto()) @map("_id") @db.ObjectId + email String @unique + name String? } From b1b048448bba49343cd8fea53fc13ef1e828b884 Mon Sep 17 00:00:00 2001 From: Seven Du Date: Sun, 24 Mar 2024 23:48:21 +0800 Subject: [PATCH 2/2] chore(version): 4.0.2 --- CHANGELOG.md | 19 +++++++++++++++++++ README.md | 2 +- docs/getting-started/index.md | 4 ++-- lib/version.dart | 2 +- pubspec.yaml | 2 +- 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f913a7d5..1f719a8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,22 @@ +# Prisma Client Dart v4.0.2 + +To install Prisma Client for Dart v4.0.2 run: + +```bash +dart pub add orm:4.0.2 +``` + +Or update your `pubspec.yaml` file: + +```yaml +dependencies: + orm: 4.0.2 +``` + +## What's Changed + +- **Bug**: Fixed the `Json` class not found in the generated code. + # Prisma Client Dart v4.0.1 To install Prisma Client for Dart v4.0.1 run: diff --git a/README.md b/README.md index 9e7f6aeb..8184f1ed 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ This will add a like this to you packages `pubspec.yaml` (and run an implicit `d ```yaml dependencies: - orm: 4.0.0 + orm: latest ``` Or you can run the following command: diff --git a/docs/getting-started/index.md b/docs/getting-started/index.md index 32ef18dc..5acb2f35 100644 --- a/docs/getting-started/index.md +++ b/docs/getting-started/index.md @@ -77,12 +77,12 @@ bun add prisma Please run the following command to install `orm`: ```bash -dart pub add orm:4.0.1 +dart pub add orm:4.0.2 ``` Or add the following to your `pubspec.yaml` file: ```yaml dependencies: - orm: ^4.0.1 // [!code focus] + orm: ^4.0.2 // [!code focus] ``` diff --git a/lib/version.dart b/lib/version.dart index 22dbe339..5cf42ff7 100644 --- a/lib/version.dart +++ b/lib/version.dart @@ -1,3 +1,3 @@ library prisma.version; -const version = '4.0.1'; +const version = '4.0.2'; diff --git a/pubspec.yaml b/pubspec.yaml index e4550461..83f3597b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: orm description: Next-generation ORM for Dart & Flutter | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB. -version: 4.0.1 +version: 4.0.2 homepage: https://prisma.pub repository: https://github.com/medz/prisma-dart funding: