medz / prisma-dart

Prisma Client Dart is an auto-generated type-safe ORM. It uses Prisma Engine as the data access layer and is as consistent as possible with the Prisma Client JS/TS APIs.
https://prisma.pub
BSD 3-Clause "New" or "Revised" License
436 stars 29 forks source link

Dart cannot generate "prisma_client.g.dart" from Prisma client #254

Closed jmakinin closed 10 months ago

jmakinin commented 10 months ago

I have a flutter application that I want to use SQLite database with Prisma ORM based on the prisma-dart package.

Everything seems to work fine until I run the command dart run build_runner build then it fails to generate the Dart Prisma client to work with the Prisma generated Client.

This is the prisma schema I'm working with for now

generator client {
  provider = "dart run orm"
}

datasource db {
  provider = "sqlite"
  url      = "file:./source.db"
}

model User {
  id        String   @id @default(uuid())
  email     String   @unique
  firstname String?
  lastname  String?
  userpass  String
  role      String
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  status    Boolean  @default(true)
  userID    String?  @unique
}

on running npx prisma generate,

the prisma client is successfully generated and expects this file

part 'prisma_client.g.dart';

however when I run

dart run build_runner build

I get the following error:

$ dart run build_runner build
[INFO] Generating build script completed, took 296ms
[INFO] Reading cached asset graph completed, took 89ms
[INFO] Checking for updates since last build completed, took 800ms
[INFO] Running build completed, took 21ms
[INFO] Caching finalized dependency graph completed, took 46ms
[SEVERE] json_serializable on lib/src/generated/prisma/prisma_client.dart (cached):

Could not generate `fromJson` code for `equals`.
To support the type `InvalidType` you can:
* Use `JsonConverter`
  https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonConverter-class.html
* Use `JsonKey` fields `fromJson` and `toJson`
  https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html
  https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html
package:class_wise/src/generated/prisma/prisma_client.dart:567:30
    ╷
567 │   final StringFieldRefInput? equals;
    │                              ^^^^^^
    ╵
[SEVERE] Failed after 83ms

I have searched online, but it seems there is very little engagement with this stack combination; any help in any form will be very much appreciated. thank you.

System:

Windows 11

$ dart --version Dart SDK version: 3.0.6 (stable) (Tue Jul 11 18:49:07 2023 +0000) on "windows_x64"

$ flutter --version Flutter 3.10.6 • channel stable • https://github.com/flutter/flutter.git Framework • revision f468f3366c (5 weeks ago) • 2023-07-12 15:19:05 -0700 Engine • revision cdbeda788a Tools • Dart 3.0.6 • DevTools 2.23.1

$ node -v v16.16.0

$ npm -v 8.11.0

dazzlemon commented 10 months ago

I had the same problem, solution from #249 (downgrade prisma in package.json to below 5.0.0) helped

vfiruz97 commented 10 months ago

+1 the same problem

jmakinin commented 10 months ago

+1 the same problem

this version of prisma worked for me

"dependencies": {
    "prisma": "^4.16.2"
  }