Skip to content

Commit

Permalink
Merge pull request #350 from medz/349-why-dont-json
Browse files Browse the repository at this point in the history
`Json` type error not found
  • Loading branch information
Seven Du authored Mar 24, 2024
2 parents 3c9f551 + b1b0484 commit 3d30cea
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 47 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pubspec.lock
example/prisma/*
!example/prisma/schema.prisma
prisma-query-*
prisma/.env*

# Prisma Engine (Rust)
target/
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions bin/src/generate_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 6 additions & 6 deletions bin/src/generate_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
}
}
Expand Down
4 changes: 2 additions & 2 deletions docs/getting-started/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
```
1 change: 1 addition & 0 deletions lib/src/runtime/prisma_json.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class PrismaJson implements JsonConvertible<Object> {
final Object value;

const PrismaJson(this.value);
const PrismaJson.fromJson(this.value);

@override
Object toJson() => value;
Expand Down
2 changes: 1 addition & 1 deletion lib/version.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
library prisma.version;

const version = '4.0.1';
const version = '4.0.2';
38 changes: 5 additions & 33 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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?
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 3d30cea

Please sign in to comment.