ujjwalguptaofficial / JsStore

Simplifying IndexedDB with SQL like syntax and promises
http://jsstore.net/
MIT License
858 stars 110 forks source link

Data may be stale #58

Closed kakugiki closed 6 years ago

kakugiki commented 6 years ago

This may not be an issue specific to JsStore, but I would like to ask your input. I use JsStore to store a query result and later update one of the records. When I use connection.select({ ... }) to retrieve the data, it's not updated. I need to search again to get the update. You call tell the idb was udpated, as it says "Data may be stale".

image

Is there a way to refresh idb before select, or something like that? Thank you very much for your time.

ujjwalguptaofficial commented 6 years ago

That means that indexeddb data in the developer tools are not latest, it mght be old. So clicking on refresh icon will fetch latest data and the warning about stale data will be gone.

The developer doesnot refresh data automatically, you need to manually refresh it.

kakugiki commented 6 years ago

No, that's is obvious. I meant to say is the view is stale. I updated the idb store with an API and want to see the update from the web page, but the select only gave me the old record.

ujjwalguptaofficial commented 6 years ago

ok so you are saying that - you update the record then select the record but you are getting old record in select right ?

kakugiki commented 6 years ago

Yup, that's it. Any idea?

ujjwalguptaofficial commented 6 years ago

Are you using transaction api ?

kakugiki commented 6 years ago

It's .net core api using Dapper.SqlMapper. Not sure does it matter since I can tell the idb is indeed updated when I refresh it from the Developer tools.

ujjwalguptaofficial commented 6 years ago

No it does not matter actually whatever backend technology we are using. I am asking about jsstore transaction api.

I believe, then your query is something like this -

connection.update({

})
connection.select({

})

Let me know. If you are using this query make sure you are using same where qry in select as in update. For confirming this do one thing - keep where query in a variable and then use that in both api.

ujjwalguptaofficial commented 6 years ago

Also turn on jsstore log and see in console how the query is being executed. For log api, check here - http://jsstore.net/tutorial/helpers/

kakugiki commented 6 years ago

OK, I guess that's the reason. I use set instead of your transaction api to update the record. It's easier to update this way: set(caseId, response[0]), where caseId is the primary key. It certainly update the record successfully as you can see the newly updated result by refresh from the Developer tools. I need to run the search again to bring the update to the web page. You can close this one then, if that's the case. Thanks for your help anyway.

kakugiki commented 6 years ago

This issue may not be directly related to JsStore. I figured it out by updating the idb and angular scope at the same time instead of only updating the idb and then retrieve the record from idb. I'll close this thread. Thank you for time!

ujjwalguptaofficial commented 6 years ago

Are you using get, set api ? Let me know.

kakugiki commented 6 years ago

I actually use idbKeyval.set(caseId, response[0]);

ujjwalguptaofficial commented 6 years ago

and what is idbKeyVal ?

kakugiki commented 6 years ago

https://github.com/jakearchibald/idb-keyval

ujjwalguptaofficial commented 6 years ago

ok I see, its another library. Sorry but I can't say anything about it. But my guess is - this issue happens when you are executing multiple query in a same transaction.

Anyway I would like you to know - jsstore also have "get", "set", api where you can store data in the form of key and value format. Here is the link - http://jsstore.net/tutorial/helpers/

kakugiki commented 6 years ago

Ok, I'll give it a try. I used that library first before I found yours. Thank you for your time.

kakugiki commented 6 years ago

should I use jsstore's set the same way as idbKeyval.set(caseId, response[0])? I tried connection.set(caseId, response[0]), but couldn't update the idb. caseId is the primary key. BTW, it should be 'value set' not 'value setted'.

ujjwalguptaofficial commented 6 years ago

I tried connection.set(caseId, response[0]), but couldn't update the idb -

I think due to the multiple library , there may be confusion, so please use one library.

BTW, it should be 'value set' not 'value setted'. -

Sorry i am not able to understand what do you mean by this. Could you please explain more ?

kakugiki commented 6 years ago

I tried connection.set(caseId, response[0]), but couldn't update the idb -