question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Access the db in native module

See original GitHub issue

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

  • Realm JS SDK Version: ?

  • Node or React Nattive: ?

  • Client OS & Version: ?

  • Which debugger for React Native: ?/None

  • Realm JS 1.10.1

  • Realm Java 3.5.0

  • React Native

  • Android Version 5.1.1

React Native

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:2
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
douglasjuniorcommented, Apr 6, 2022

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

1reaction
kristiandupontcommented, Aug 16, 2017

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create native module to retrieve realm data value in ...
You have two options. Automatic or manual link. 1) Automatic: You just run "react-native link "npm-module". It should do it for you.
Read more >
A framework for building native apps using React - Deco IDE
We start by creating a native module. A native module is a Java class that usually extends the ReactContextBaseJavaModule class and implements the...
Read more >
How to get data from an MySQL database in React Native
In your React Native project (you can place it anywhere you want tho), create a file named 'routes.js'. This will be our server...
Read more >
iOS Native Modules
The native module can then be accessed in JS like this: const {CalendarModuleFoo} = ReactNative ...
Read more >
React Native — Native Modules - Medium
getName() method. This method returns a string, which represents the name of the native module. with that name, the native module can be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found