Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to get data #7

Closed
apppro123 opened this issue Nov 28, 2018 · 10 comments
Closed

Unable to get data #7

apppro123 opened this issue Nov 28, 2018 · 10 comments

Comments

@apppro123
Copy link

var TodoSchema = {
name: "Todos",
props: {
name: "string",
note: "?string",
completed: "boolean"
},
};

    const VasernDB = new Vasern({
        schemas: [TodoSchema],
        version: 1
    });
    
    const { Todos } = VasernDB;
    
    
    var item1 = Todos.get({ name: "Setup database for React Native" });
    console.log(item1);
    Todos.remove(item1);
    console.log(Todos._data);
    console.log(Todos.available);

At the moment i cannot perform for example
Todos.data() or Todos.get({ name: "Setup database for React Native" }) or Todos.remove() doesnt work!!

it runs when i want to get Todos._data, but i just get an empty list but when i just want to get Todos i see under the object, that there should be 7 items in the list
and also Todos.available is false but in the object Todos it is true!?

@hieunc229
Copy link
Contributor

Since it caused by detaching Queryable from Document (remove Document.import(Queryable)). I'll close this issue and continue to troubleshoot the issue in #6

@hieunc229 hieunc229 changed the title Actions Unable to get data Nov 29, 2018
@hieunc229
Copy link
Contributor

I also have update issue name with a more meaning description!

@apppro123
Copy link
Author

Sorry that i have to reopen this issue, but i just noticed, that i still cannot get the data with .data(). But unter the object are a lot of element (under _data)!
Maybe in the functin data() there is a false syntax (maybe the "this" is not related to the object or so).

@hieunc229
Copy link
Contributor

Hi @apppro123, have you try to use ‘onLoaded’?

Here is an example #5 (comment)

@apppro123
Copy link
Author

Now it is working! Is this because the db is not loaded after app starts (i want to access data() in componentDidMount()) ?
And why is it showing the right data in the object?

@hieunc229
Copy link
Contributor

Raw data is loaded before the app started. It will be serialised after the app started, then become available to use.

On your componentDidMount(), you can use ‘.data()’ within ‘.onLoaded’ callback.

I didn’t get what you mean by ‘showing data in the object’. Can you explain a bit more? Thanks!

@apppro123
Copy link
Author

With that i mean if i make console.log(Calendar) it shows all properties and under _data i can the calendar-Objects in an array. But with console.log(Calendar.data()) it just gives a empty array.
A little bit weird for me :)

@hieunc229
Copy link
Contributor

hieunc229 commented Jan 1, 2019

If you use .data() inside onLoaded event, does it still show an empty result?

Use .data() will ensure data is properly serialised correctly.

@apppro123
Copy link
Author

Inside the onLoaded it is working correctly. But it is strange that data() doesnt work without onLoaded but if i just show the object (console.log(Calendar)) there under _data it shows the right array and that is also without onLoaded!?

@hieunc229
Copy link
Contributor

The reason .data() not working without .onLoaded because when the app started, it fetches raw data and saves it in _data. Then it will serialize records one by one. When all records are serialized, .data() will be able to return records.

So it is safe to use .data(). Otherwise, if the serialize records is not completed, you might get unserialized records.

I would recommend you to use .data() inside .onLoaded because once the database size grows big. The serialize process will take more time. You will not receive correct records using _data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants