I am using Realm JS with my React Native app. I had inserted a value in my schema as follows.
const CarSchema = {
name: 'Car',
properties: {
model: 'string'
}
};
let realm = new Realm({schema: [CarSchema]});
realm.write(() => {
realm.create('Car', {
model: 'Ford'
});
});
let cars = realm.objects('Car');
console.log(cars);
In the Chrome console I get the following object instead of all the cars in the db.
Am I missing something here?
The Proxy object allows you to create an object that can be used in place of the original object, but which may redefine fundamental Object operations like getting, setting, and defining properties. Proxy objects are commonly used to log property accesses, validate, format, or sanitize inputs, and so on.
Proxy is an object in javascript which wraps an object or a function and monitors it via something called target. Irrespective of the wrapped object or function existence. Proxy are similar to meta programming in other languages.
Realm is a mobile database that runs directly inside phones, tablets or wearables. This project hosts the JavaScript versions of Realm. Currently we support React Native (both iOS & Android), Node.
This is a consequence of how Realm objects work (as well as Lists and Results) - instead of hydrating data from the database and deserializing (potentially) a ton of objects, Realm gives you lazily-loaded objects and collections. Realm.objects('Car')
doesn't return a JavaScript array, but a Results
object - it still behaves exactly like an array, but it's not implemented using the built-in array object. That's why it doesn't look like an array of objects in the Chrome console, even though it behaves the same.
You can, however, eagerly read a Realm collection in an Array with Array.from(realm.objects('Car'))
and that will visualize better in the debugger.
"Proxy" objects are the corner-stone of Realm and its zero-copy philosophy. All the Realm SDKs are implemented the same way - instead of plain objects subject to serialization and deserialization, you get proxy objects that access the database directly.
In realm-js the actual proxying mechanism works differently based on whether your code runs on React Native, Node.js, or the React Native Chrome debugger, so the implementation details of these proxies are going to differ.
The problem with all this is that it doesn't display as nicely in a JavaScript debugger. Unfortunately I'm not aware of a way to influence the way Chrome displays objects in the debugger.
Source: I'm a realm-js contributor.
The code seems fine, I used a similar snippet in my project as well
The above image is similar to what you showed above.
The exanded version should contain all the objects of Car. In my case the properties has key and value under object 0. In your case it should have model: "Ford" in one the results.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With