I've tried to use Realm in my project with very little success and I'm lost with this.
I followed this tutorial: https://medium.com/@bosung90/tackling-react-native-storage-part-1-d27b2bfa480f with no luck, and also the official documentation: https://realm.io/docs/javascript/latest/
Defining a realm and writing to it seems to work, but I can't read data from it.
My code for creating the database:
const userSchema = {
name:'User',
properties:{
name:'string',
phone:'string',
loggedIn:{type:'bool', default:false}
}
};
const realm = new Realm({schema: [userSchema]});
And here's the reading function:
export function getUsers(){
Realm.open({schema: [userSchema]})
.then(realm => {
const users = realm.objects('User');
return users;
});
}
So here are some questions:
In the getUsers function, realm.objects does not return any results, but instead:
Proxy {-1: undefined, Symbol(realm): 10, Symbol(id): 14, Symbol(type): "results", …} [[Handler]]:Object [[Target]]:Results [[IsRevoked]]:false
How can I get the actual results instead?
Do I have to use
Realm.open()
every time I do anytihing with the database?Can someone give an example of code and files where Realm DB is created, data is written and data is fetched, please?
Any kind of help is highly appreciated.