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
460 stars 31 forks source link

Raw prisma engine protocol query #281

Open MulverineX opened 1 year ago

MulverineX commented 1 year ago

There should be a supported way to run queries directly to the prisma engine.

Once #328 is resolved I'm planning on using this library as a host for an internal prisma client in JavaScript, running in QuickJS via an upcoming library, mercury. Its a rather novel/obscure usecase, but I would appreciate not having to use internal methods of the library that may change.

medz commented 1 year ago

Yes, I'm working on a new engine, but the API is no longer consistent with the Prisma TS/JS client 👉 https://github.com/medz/prisma-dart/issues/277

The decision is a difficult one, as new client constructs are made in a way that is suitable for Dart or other languages that do not have Union types. Of course, it's not absolute, I have plans to support Union types in Dart (https://github.com/dart-lang/language/blob/main/working/union-types/nominative-union-types.md) Make it consistent with the Prisma TS/JS client API, which makes learning Prisma easier.

But progress is indeed a bit slow now. The new client API, although suitable for Dart, has completely deviated from Prisma AST and I need to do a lot of development work in the generator.

Additionally, I needed to write a new query engine for the Prisma engine so that it could be embedded in Flutter.

The old version only allowed the use of the Prisma binary engine in Dart Native.

I plan to allow Prisma to be used in any environment in the new version. My progress is about 30%. Please give me another month or so to implement it. I think I can initially launch Flutter Prisma and Dart native Prisma.

MulverineX commented 1 year ago

So is the plan not to bind the rust engine binary for all platforms?

medz commented 1 year ago

So is the plan not to bind the rust engine binary for all platforms?

Dart native compilation does not support including other binaries, the plan for this is this:

Except for the Web, you need to use Rust to rebuild the dynamic library version of the Prisma engine.

medz commented 1 year ago

There's another reason: I don't know how to start an HTTP service on the platform Flutter is running on by running a platform binary, which is how the Prisma binary engine works.

MulverineX commented 1 year ago

Ideally, direct queries to the engine would be made, rather than having to use the HTTP server

The way I'm going to make it work for my project is by using http overrides in Mercury, a local webserver would be an unnecessary overhead and security risk.

Eventually I will contribute to the JS Prisma client and add a custom request handler, so I don't need to use the HTTP override.