realm / realm-dart

Realm is a mobile database: a replacement for SQLite & ORMs.
Apache License 2.0
758 stars 85 forks source link

Web support #26

Open maxkrieger opened 3 years ago

maxkrieger commented 3 years ago

Since Realm already has a JS client, would it be easy enough to add a web compatible variant to this package?

richard457 commented 3 years ago

This would be awesome

blagoev commented 3 years ago

We are certainly interested in supporting Flutter Web as a platform but it will require web assembly support and our Core team is exploring the various options we have. This is still at very early stages of research so we can't do any commitments currently

cedvdb commented 3 years ago

wouldn't js with indexedDB be enough ? Last I checked the js client was just allowing graphql queries

calvintam236 commented 3 years ago

wouldn't js with indexedDB be enough ?

I think the point is to have a cross-platform database on Flutter (android, ios, web and other supported platforms).

markbreuss commented 2 years ago

Would love to see web support as well!

hmbenhaim commented 1 year ago

Hi, any updates on this one?

dotjon0 commented 1 year ago

From a local persistent DB perspective; not sure how beneficial this is for Flutter Web as persistent local databases in web browsers are usually not a great approach from a data security perspective...

hmbenhaim commented 1 year ago

From a local persistent DB perspective; not sure how beneficial this is for Flutter Web as persistent local databases in web browsers are usually not a great approach from a data security perspective...

From what I understand the web support in general of realm is not local db just a sync from the cloud and it's available for js just ask to add it to flutter web

https://www.mongodb.com/docs/realm/web/

ajonno commented 1 year ago

they should add support for GraphQL subscriptions

JakobStadlhuber commented 1 year ago

Any updates? web assembly is now in a further stage with flutter web since the last keynote a couple weeks ago.

nirinchev commented 1 year ago

Support for web assembly is not on our short-term roadmap. As @blagoev said, we are interested in eventually supporting it as a platform and are doing some preliminary work there, but we don't currently expect this to materialize in something user-facing before the end of 2023.

If you would like to use App Services in a web assembly project, the recommendation is to use GraphQL or the Data API which are both accessible using a simple http client or via a 3rd party package, such as graphql_flutter.

JakobStadlhuber commented 1 year ago

I understand. I just wanted to make it clear that there is a big opportunity in the growing flutter community for you. Developing once for Web, App, and the Desktop Client with realm/app service as a backend/data solution sounds amazing. We will probably use it anyway but we have to write a separated codebase just for the web, because there is no web support with flutter realm. I hope you see the big potential with really just one codebase for companies/startups....

nirinchev commented 1 year ago

We are aware of it and are definitely interested in catering to the needs of businesses that would like to share a codebase between their native and web apps. The main blocker here is that the database as well as the sync layer is written in C++ (in order for us to share it across all supported platforms). Web Assembly imposes certain restrictions/has some peculiarities when it comes to IO and multithreading that require significant work to support. We're working on it and making some progress there, but I wanted to be upfront about the timelines so that you folks can make the best design choices for the architecture of your project. If you're looking to ship something in the next 3-6 months, it would be a mistake to wait for WebAssembly support in the Flutter SDK. If you're working on a huge project that will ship in 2024 or later, then definitely reach out to your account executive (if using any of our paid services) and they should be able to work with you and share more precise timelines as well as relay your requirements to the engineering team.

realrk95 commented 1 year ago

Now that Flutter 3.10 is released and supports WASM, would it be possible to use Realm on web?

minikin commented 1 year ago

@realrk95 It has limited support. I believe adding support for the web is still a challenging task.

nielsenko commented 1 year ago

For the interested (in case you missed it) there is a preview in the realm-js SDK for for proper Realm support including full Atlas Device Sync. This is based on compiling realm-core to wasm with emscripten. Take note that it has significant limitations.

NOTE: It is only for javascript, not Dart.

aehlke commented 1 year ago

@nielsenko not sure where's best to give this feedback, but the next absolute game changer would be to figure out how to connect other wasm efforts such as SwiftWASM into this new realm-js work such that Swift code (or other langs which Realm supports) can be used for both mobile and web including the Realm usage. JS is great for cross-platform, but there are many Swift / native app developers who are looking for cross-plat solutions too and this brings us closer to that. Thanks

nielsenko commented 1 year ago

@aehlke I'm not familiar with SwiftWASM, but feel free to open a feature request in https://github.com/realm/realm-swift

zs-dima commented 1 year ago

@nirinchev @blagoev You can see nice solution that uses Wasm SQLite or IndexedDB depends on web browser: Drift library: https://drift.simonbinder.eu/web/#storages

nielsenko commented 1 year ago

@zs-dima I'm well aware of the work of Simon Binder (@simolus3). I used to use Drift (or moor as it was called back then) a lot. Another database that support web is isar by Simon Choi (@simc). I can highly recommend both, if synchronisation is not important to you, and you need web support now.

zs-dima commented 1 year ago

@nielsenko thanks a lot for the answer, I cannot reccommend ISAR alghthough. It has critical issues with isolates for example. https://github.com/isar/isar/issues/1112 https://github.com/isar/isar/issues/1199 . . . In the same time community and all my projects are happy with Drift. Sorry for the offtopic.

nielsenko commented 1 year ago

@zs-dima Please observe https://www.mongodb.com/community-code-of-conduct. I can't speak for @nirinchev, but I stand by my word.

rodrigoreal commented 7 months ago

Any update on this?

nirinchev commented 7 months ago

When we have an update, we will be sure to post it in the issue.

juppdes commented 6 months ago

Sorry for my ignorance, but why doesn't it work on web apps?

nirinchev commented 6 months ago

The Realm database is built in C++ and the features it uses - particularly around filesystem access - are not available in the web. The Realm Flutter SDK is wrapping the C++ database to expose ergonomic API to read/write data from dart/flutter apps, but the platforms we support are limited by the platforms the native database supports.

nielsenko commented 6 months ago

To elaborate on @nirinchev's answer.

We would need to compile realm-core (or actually librealm_dart.so which includes the former) to WASM. Some ground work has been done to this end, but we are not done.

One complication is that realm uses mmap'ed IO, which is not supported by the WASM runtimes of the browsers. We either need to

Also, we are using dart:ffi to call into native code. Dart FFI is not supported with Flutter Web (yet). This means we will have to manually create a JS interop based binding instead.

Add on top of this that some browsers still don't even support WasmGC - which is pre-requisite for compiling flutter code to WASM. This means we would have to support compiling to javascript, just to run in Safari. Or any browser on iOS, as they all forced to use WebKit (except in the EU as of iOS 17.4). Which again will require some work-around regarding the dreaded 53 bit integers.

This is just a lot of risky external dependencies, and/or a ton of work that has to be prioritized among other stuff. That said, we are well aware that this is the most upvoted feature in the repo. So stay tuned, but be very patient 🙏 ..