fetch from api then save to indexdb?
gotexis opened this issue · 3 comments
How to do that...
Or maybe I misunderstood? Is the project not for syncing with an external API?
Typing full-caps isn't going to get your issue solved faster and only annoys people who read it.
Or maybe I misunderstood? Is the project not for syncing with an external API?
You likely have misunderstood. This library is not for syncing across a restful API, but for persisting data to LocalForage.
The way you'd go at this is as follows:
- Get data from an (external) API using for example Axios to handle the HTTP calls.
- If required, manipulate or parse the data
- Save the data to vuex through the vuex orm models, using the extra functions this package provides.
- Using for example
Model.$create(...)
instead ofModel.create(...)
will result in the data you pass into it to be saved in both the vuex storage, as well as in the LocalForage database.
sorry
I am also using Vuex-ORM[+GraphQL] and loving what I saw so far. I believe this is a promising project that has a future.
I believe I must have misunderstood something here.
VuexORM lets you fetch from GraphQL, save to VuexORM.
then natually I assume this package will allow you to save that data just fetched to localstorage / IndexDB.
So the goal is really to cache API queries and ease server load (I believe the case is quite common).
persisting data to LocalForage.
So did you mean persist the data that user have created, instead of persisting the data grabbed from API?
Right now I actually can persist data into Vuex by using Vuex-persistedstate, but I'm guessing I will be missing some key features this plugin can provide.
It depends on how the GraphQL plugin is saving data into Vuex-ORM. I've tried working with multiple Vuex-ORM plugins before, and that didn't go very well. (they conflicted with each other)
When loading data, you can persist that with LocalForage using the Model.$create()
method that this plugin adds. It's a copy of the Vuex ORM Model.create()
, so you can insert multiple lines at once using this:
Model.$create({
data: [
{ ... },
{ ... } // and so on
]
})
And later on fetch the data from LocalForage with a Model.$fetch()
, which grabs all data from this model, pulls it from the storage and saves it to Vuex.