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
452 stars 30 forks source link

Error when running "npx prisma db push" - Type 'Null' is not a subtype of type 'bool' in type cast #259

Closed dutrapaulovm closed 10 months ago

dutrapaulovm commented 1 year ago

I was following this Prisma Dart tutorial: https://prisma.pub/docs/getting-started.html And,

After executing the npx prisma db push command, the following error is generated:

Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Datasource "db": MySQL database "contas_receber" at "localhost:3306"

The database is already in sync with the Prisma schema.

Running generate... (Use --skip-generate to skip the generators)
Building package executable... (4.6s)
type 'Null' is not a subtype of type 'bool' in type cast

My prisma.schema

generator client {
  provider = "dart run orm"
}

datasource db {
  provider = "mysql"
  url      = "mysql://root:root@localhost:3306/contas_receber"
}

model cliente {
  CODCLIENTE   Int      @id @default(autoincrement())
  NOME         String   @default("") @db.VarChar(500)
  CPFCNPJ      String   @default("") @db.VarChar(20)
  ENDERECO     String   @default("") @db.VarChar(500)
  CONTATO      String   @default("") @db.VarChar(500)
  DATACADASTRO DateTime @default(now()) @db.DateTime(0)
  pedido       pedido[]
}

model contasreceber {
  CODCONTASRECEBER Int         @id @default(autoincrement())
  CODPEDIDO        Int
  DATAEMISSAO      DateTime    @default(now()) @db.DateTime(0)
  DATAVENCIMENTO   DateTime    @default(now()) @db.DateTime(0)
  VALOR            Float       @default(0)
  VALORRESTANTE    Float       @default(0)
  STATUSPAGAMENTO  String      @default("") @db.VarChar(1)
  pedido           pedido      @relation(fields: [CODPEDIDO], references: [CODPEDIDO], onUpdate: Restrict, map: "FK_CONTASRECEBER_PEDIDO")
  pagamento        pagamento[]

  @@index([CODPEDIDO], map: "FK_CONTASRECEBER_PEDIDO")
}

model itenspedido {
  CODITENSPEDIDO Int     @id @default(autoincrement())
  CODPEDIDO      Int
  CODPRODUTO     Int
  QUANTIDADE     Int     @default(0)
  PRECOUNITARIO  Float   @default(0)
  VALORTOTAL     Float   @default(0)
  pedido         pedido  @relation(fields: [CODPEDIDO], references: [CODPEDIDO], onUpdate: Restrict, map: "FK_ITENSPEDIDO_PEDIDO")
  produto        produto @relation(fields: [CODPRODUTO], references: [CODPRODUTO], onUpdate: Restrict, map: "FK_ITENSPEDIDO_PRODUTO")

  @@index([CODPEDIDO], map: "FK_ITENSPEDIDO_PEDIDO")
  @@index([CODPRODUTO], map: "FK_ITENSPEDIDO_PRODUTO")
}

model pagamento {
  CODPAGAMENTO     Int           @id @default(autoincrement())
  CODCONTASRECEBER Int
  DATAPAGAMENTO    DateTime      @default(now()) @db.DateTime(0)
  VALORPAGO        Float         @default(0)
  contasreceber    contasreceber @relation(fields: [CODCONTASRECEBER], references: [CODCONTASRECEBER], onUpdate: Restrict, map: "FK_PAGAMENTOS_CONTASRECEBER")

  @@index([CODCONTASRECEBER], map: "FK_PAGAMENTOS_CONTASRECEBER")
}

model pedido {
  CODPEDIDO     Int             @id @default(autoincrement())
  CODCLIENTE    Int
  DATAPEDIDO    DateTime        @default(now()) @db.DateTime(0)
  VALORTOTAL    Float           @default(0)
  contasreceber contasreceber[]
  itenspedido   itenspedido[]
  cliente       cliente         @relation(fields: [CODCLIENTE], references: [CODCLIENTE], onUpdate: Restrict, map: "FK_PEDIDO_CLIENTE")

  @@index([CODCLIENTE], map: "FK_PEDIDO_CLIENTE")
}

model produto {
  CODPRODUTO  Int           @id @default(autoincrement())
  NOME        String        @default("") @db.VarChar(500)
  DESCRICAO   String        @default("") @db.VarChar(500)
  PRECO       Float         @default(0)
  itenspedido itenspedido[]
}
medz commented 1 year ago

Using Prisma CLI 4.x version

dutrapaulovm commented 1 year ago

I'm using prisma 5.2.0

medz commented 1 year ago

I'm using prisma 5.2.0

Unfortunately, Prisma for Dart does not currently support Prisma 5.x version (due to huge changes). Also you should see my tweets, I am now committed to my normal life due to the bankruptcy of my company. I'm really sorry, I don't know when I will have time to come back and continue to maintain it, but I have always paid attention to this project. Once I get my debt out of the way, I'll go back to open source and continue maintaining Prisma for Dart.

dutrapaulovm commented 1 year ago

What version of Prisma can I use?

medz commented 1 year ago

What version of Prisma can I use?

Prisma 4.x in your package.json

dutrapaulovm commented 1 year ago

What version of Prisma can I use?

Prisma 4.x in your package.json

Thanks!!!

egyleader commented 1 year ago

same issue , resolved by downgrading to 4.16.0

alestiago commented 1 year ago

I think this is a duplicate of #249

@medz I've seen that this is tagged as a good first issue. I'm interested in CONTRIBUTING for the first time in this project, are there any instructions, recommendations and pointers to set everything up locally?

medz commented 1 year ago

I think this is a duplicate of #249

@medz I've seen that this is tagged as a good first issue. I'm interested in CONTRIBUTING for the first time in this project, are there any instructions, recommendations and pointers to set everything up locally?

@alestiago That's really great, but at the moment I can't provide a more detailed way to get involved in the project. Because this is an exploratory process, let me briefly explain how I developed this project:

  1. I downloaded the Prisma binary during development, and then explored it through the --help parameter (because Prisma officially did not provide relevant technical information)
  2. I found that it can run a GraphQL server and run a JSON API server (after version 5.2) for proxying database queries.
  3. I tried to read the DMMF of the TS source code and the Prisma TS client source code to understand its operating logic.
  4. I operate the Prisma binary engine in Dart by adding parameters to run it in the system, and then it serves the Dart client (because the started port is only known by the program when I start it)
  5. I write general client code and interface abstraction in the lib directory
  6. I wrote the code to temporarily start the Prisma binary engine in the bin directory, and obtained DMMF through CLI operations. DMMF is an abstract structure that conforms to GraphQL Nodes. I use this data to generate Dart code using code_builder.

Problems encountered with this version now:

  1. Prisma 5.x no longer starts the GraphQL protocol by default, but the JSON protocol server. The fix is to add a new parameter when starting the Prisma engine.
  2. You need to adapt to the JSON protocol as soon as possible. This is a completely new exploration process without any useful reference materials.
  3. My company went bankrupt and I am currently solving my debt problem, which is why this project was suddenly suspended two months ago.

Information to help you get started quickly:

https://github.com/prisma/prisma/tree/main/packages/engines

That's right, it's the source code of Prisma's official client.

medz commented 1 year ago

@alestiago The local setting of this project is also very simple:

  1. npm install
  2. dart pub get

That's all. You can run npx prisma generate --watch directly at the project root to test the generator. If you want to verify the API availability, you can usually run it again in example.

medz commented 1 year ago

Another challenge in making CRUD ORM in Dart is Union-Type. I have been waiting for this feature, so now the input production code of multiple types becomes very complicated.

alestiago commented 1 year ago

@medz thank you for the information provided. I will let you know if I give it a go and raise a Pull Request when ready 🙌 . Regarding your debt problem, are you open to sponsorships to continue the development/maintenance of Prisma-Dart?

medz commented 1 year ago

@alestiago It is difficult to make money from open source and the user base of Prisma Dart is too small, especially since I am in an environment where capital is not optimistic about technology entrepreneurship. It's difficult to solve my debt problem through sponsorship, you know, the amount of money required for a company is huge. In the two months since Prisma Dart stopped updating, I have settled nearly 1 million in debt, and I think I will need another month or two. When I completely pay off my debt, I will give up entrepreneurship and find a job, and then use my spare time every day to maintain this project.

Also, I look forward to your PR requests. Because I like Dart very much, I have never planned to give up this project and want to maintain it. When you notify me that you can review, I will deal with it as soon as possible.

AndryHTC commented 12 months ago

@medz thank you for the information provided. I will let you know if I give it a go and raise a Pull Request when ready 🙌 . Regarding your debt problem, are you open to sponsorships to continue the development/maintenance of Prisma-Dart?

A big project waiting here! 😃 @alestiago thanks in advance!

medz commented 11 months ago

I'm actively developing a new version to adapt to Prisma 5

alestiago commented 11 months ago

@medz that's great news! I've haven't started that on my end yet. Is there a branch I can track your changes?

medz commented 11 months ago

@medz that's great news! I've haven't started that on my end yet. Is there a branch I can track your changes?

main branch, main is dev branch and latest version branch. 3.x is old version branch.

After a few days of research, I discovered that Prisma caused so much change that a new version was almost equivalent to a rewrite. But I will try to reduce the difficulty of migration as much as possible, and the API will not change much. But a lot of things will be built into it that are better suited to the Dart language, not just a clone of the Prisma JS/TS client.

Firephoenix25 commented 11 months ago

I donwgraded to 4.16 and i get a different error

I get the error "Could not find query engine for platform darwin"

Is the because there's is not compatible to m1 silicon chip in my macbook?

medz commented 11 months ago

I donwgraded to 4.16 and i get a different error

I get the error "Could not find query engine for platform darwin"

Is the because there's is not compatible to m1 silicon chip in my macbook?

You try reinstalling prisma, because I have limited energy alone. In order to keep up with prisma quickly, I haven't found any problems with the v3.x version. Because the update of prismna 5.x is too big.

medz commented 11 months ago
image

Report the progress:

I'm developing the JSON protocol enabled by Prisma 5 and I'd like to hear your opinions on the final API build.

AndryHTC commented 11 months ago

I'd like to hear your opinions on the final API build

A question with a more limited reply context could help a bit :)

medz commented 10 months ago

@AndryHTC @dutrapaulovm @alestiago Fixed, The 3.x version will be updated later