realm / realm-js

Realm is a mobile database: an alternative to SQLite & key-value stores
https://realm.io
Apache License 2.0
5.69k stars 563 forks source link

Access the db in native module #1212

Open hellomaya opened 6 years ago

hellomaya commented 6 years ago

Goals

When I have a lot data in Realm DB, and I need to do some statistics on them, for example, SUM them all, this time, doing this at javascript become pretty slow, looks like UI is frozen. So I am thinking, is it possible to access Realm DB in a native module and then doing this data processing there?

Expected Results

I am expecting that the Realm could support this, as I can access the Realm default db at native module, and then I found that's not connivence.

Actual Results

In Android scenario, the java API from Realm docs, provide way to access the data, but it required defined Model to access, like this:

public class Person extends RealmObject {
  private String id;
  private String name;
  private RealmList<Dog> dogs;
  // getters and setters
}

realm.where(Person.class)
                                .equalTo("dogs.color", "Brown")
                                .findAll();

So now the problem is, the Realm Schema already defined in javascript, then if I was going to write a certain native module to access the db at Java, I will have to define them all in Java too, and then try to query the data.

So is it possible to have some API to query the db directly by using schema name too? Just like it was in javascript, Realm.objects(schemaName)...

Steps to Reproduce

Code Sample

Version of Realm and Tooling

React Native

hellomaya commented 6 years ago

I have found the solution to use DynamicRealm:

https://realm.io/docs/java/latest/#dynamic-realms

Thanks.

hellomaya commented 6 years ago

I have tried in java, and it's working well, and then I tried Realm objc framework, not success, also address the issue I have had to access Realm DB in native module by using Realm-Cocoa framework, and it appears, not supported this time. I am hoping one day, Realm JS can provide a way to access the db from Native Module also with Dynamic Realm ability, so it's able to move some of heavy computing code from JS to Native, then promoting the performance of the app, increasing flexibility of the Realm JS.

Thank your guys for this great library, in my practice with a production app with a lot statistics, it's running and performing pretty well, especially highly promoted the productivity than using Sqlite.

I will re-open this issue somehow waiting for update.

https://github.com/realm/realm-cocoa/issues/5233#issuecomment-322597215

kristiandupont commented 6 years ago

Thank you for your input. I see the use case but as Mark points out, it will be difficult to make it work not just initially but continuously as you will have to make sure that the cocoa and js versions of Realm use the same version of the Realm core. As we don't (currently, maybe that will change) have synchronized release schedules, upgrading the Realm library will be a tedious process.

hellomaya commented 6 years ago

Got it! I am thinking to work around this by adding some code in current Realmjs native module by accessing db in objc, just like Realm-Cocoa do, I guess it's possible, as they used same core, well not sure for now, but totally support your team decision.

saadqbal commented 4 years ago

Hi @hellomaya Did you find a solution to use realm db on the native side?

VittoriDavide commented 2 years ago

Any news on this ?

douglasjunior commented 2 years ago

I'm also really looking forward to this possibility.

Since React Native does not have an official way of processing background tasks on iOS, this job needs to be done in native code.

However, without access to the Realm in the native code, it is impossible to synchronize information, etc.

sync-by-unito[bot] commented 2 years ago

➤ Kenneth Geisshirt commented:

We haven't looked at recently.

IuriKintschev commented 2 years ago

any news on this topic?

douglasjunior commented 2 years ago

Guys, please "thumb up" this issue to get the Realm team attention.