Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can this be used for an offline Flutter app? #118

Closed
BradyEdgar94 opened this issue Feb 12, 2023 · 13 comments
Closed

Can this be used for an offline Flutter app? #118

BradyEdgar94 opened this issue Feb 12, 2023 · 13 comments

Comments

@BradyEdgar94
Copy link

I am looking to convert my Flutter app to be offline first, which means migrating from my GraphQL API(using Prisma) to a local DB Flutter solution. This Prisma-Dart package would be perfect for me if it means a user can have their own DB records stored on their phone. So I am trying to see if that is possible with this package.

My requirements are to have a persistant local DB and handle CRUD operations using this prisma-dart package.

Is this something that is possible with this package?

Thanks so much!

@medz
Copy link
Owner

medz commented Feb 12, 2023

This is in the support plan. I am in the official Prisma discussion group. It is expected that the dynamic library support will be standardized in the future, then this function will become a reality.

@SpongeManiac
Copy link

It would be very helpful if this was explicitly mentioned as a limitation to this package. I have spent the last week developing around this because I thought it was a complete port of the JavaScript Prisma, allowing for local databases, but as I have just found out the hard way, this is not implemented. Here is the error I received before looking this up:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PrismaInitializationException: Cannot find the query engine binary (Basename: D:\GitHub\flutter-ws-test\node_modules\prisma\query-engine-windows.exe)
E/flutter (10903): #0      BinaryEngine.resolvedExecutable (package:orm/binary_engine.dart:79:5)
E/flutter (10903): #1      BinaryEngine._createProcess (package:orm/binary_engine.dart:178:7)
E/flutter (10903): #2      BinaryEngine.start (package:orm/binary_engine.dart:148:23)
E/flutter (10903): <asynchronous suspension>
E/flutter (10903): #3      UniversalEngine.request (package:orm/universal_engine.dart:59:5)
E/flutter (10903): <asynchronous suspension>
E/flutter (10903): #4      ModelDelegate._execute (package:orm/src/client/model_delegate.dart:40:20)
E/flutter (10903): <asynchronous suspension>
E/flutter (10903): #5      PrismaFluent.queryBuilder.<anonymous closure> (package:orm/src/client/prisma_fluent.dart:37:22)
E/flutter (10903): <asynchronous suspension>
E/flutter (10903): #6      PrismaFluent.queryBuilder.<anonymous closure> (package:orm/src/client/prisma_fluent.dart:37:22)
E/flutter (10903): <asynchronous suspension>
E/flutter (10903): #7      PrismaFluent.queryBuilder.<anonymous closure> (package:orm/src/client/prisma_fluent.dart:37:22)
E/flutter (10903): <asynchronous suspension>
E/flutter (10903): #8      PrismaProvider.preferencesExists (package:flutter_ws/platform/io/prisma/prisma_provider.dart:74:12)
E/flutter (10903): <asynchronous suspension>
E/flutter (10903): #9      PrismaProvider.ensurePreferences (package:flutter_ws/platform/io/prisma/prisma_provider.dart:78:10)
E/flutter (10903): <asynchronous suspension>
E/flutter (10903): #10     PrismaProvider.init (package:flutter_ws/platform/io/prisma/prisma_provider.dart:109:5)
E/flutter (10903): <asynchronous suspension>
E/flutter (10903): #11     AppImpl.main (package:flutter_ws/platform/io/platform_io.dart:114:5)
E/flutter (10903): <asynchronous suspension>
E/flutter (10903): #12     PlatformApp.startApp (package:flutter_ws/platform_app.dart:12:5)
E/flutter (10903): <asynchronous suspension>
E/flutter (10903): #13     main (package:flutter_ws/main.dart:7:3)
E/flutter (10903): <asynchronous suspension>

I'm still looking for a decent ORM for local databases. I'll be switching to Drift in the mean time.

@medz
Copy link
Owner

medz commented May 18, 2023

@BradyEdgar94 @SpongeManiac
Currently Flutter only supports Data Proxy, please use --data-proxy when generating the client
Docs: npx prisma generate --data-proxy -> https://www.prisma.io/docs/data-platform/about

Unfortunately, Library has not been developed yet because I am new to Rust.

@medz
Copy link
Owner

medz commented May 18, 2023

image

@MulverineX
Copy link
Contributor

I was curious what the current status of this is? The Engine Binary being supported on Flutter Native, that is. Is there any documentation or prior examples of this being done in other languages? I'd love to help.

@medz
Copy link
Owner

medz commented Oct 28, 2023

I was curious what the current status of this is? The Engine Binary being supported on Flutter Native, that is. Is there any documentation or prior examples of this being done in other languages? I'd love to help.

Flutter does not support binary engine files, and Prisma engines https://github.com/prisma/prisma-engines are not ready to be built for CAPI. In other words, if I want to provide an offline local database for Prisma Support, I have to write a CAPI engine whose output target is a dynamic library (so/dll), which is cumbersome, but I'm working on it, I'm building the new Prisma client API, and when it's finished, I can start building the engine part .

@medz
Copy link
Owner

medz commented Oct 28, 2023

One reason, as mentioned above, is that I am new to Rust. This was a big challenge for me, as I needed to learn the Rust language and develop it at the same time.

@MulverineX
Copy link
Contributor

I'm actually doing a similar thing with Mercury, I've never worked with C++ before, but I had to for the project. I wouldn't mind having to do that again for this project, I'd love to know how/if I could help!

@listepo
Copy link

listepo commented Dec 17, 2023

https://pub.dev/packages/flutter_rust_bridge maybe can help

@medz
Copy link
Owner

medz commented Dec 18, 2023

https://pub.dev/packages/flutter_rust_bridge maybe can help

After I communicated with the Prisma Team, they have started working on the experimental C ABI engine 👉 https://github.com/prisma/prisma-engines/tree/osp/rn/query-engine/query-engine-rn They have already made it Added to this quarter’s roadmap!

image Please wait patiently, 4.0 will finally use the C ABI engine officially produced by Prisma, so that it can run in Flutter.

@medz
Copy link
Owner

medz commented Dec 18, 2023

In addition, I am making a temporary replacement version https://github.com/medz/prisma-dart/tree/main/packages/engine_ffi until the C ABI engine is officially released. Since I am new to Rust, my progress may be slow.

@medz
Copy link
Owner

medz commented Dec 18, 2023

An alternative is to wait for the Dart team to implement dart-lang/sdk#51383 this feature. At that time, I will make a Dart NAPI compatible program that can run in Dart using the Node API's dylib. However, it is obvious that Prisma Team will implement the C ABI engine faster.

@medz
Copy link
Owner

medz commented Jan 25, 2024

#328

@medz medz closed this as completed Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants