Problem with my app architecture and SQLite

Hello there,

Recently i’ve implemented SQLite databases in my app. Previously i was using a factory to store an object of ~1000 entries. The main reason that i’ve changed to SQLite instead of the hard coded object, is that said object needs to be updated over time and stored on device according to an API.

The first problem i encounter is that when i start my app, the first controller gets the information of that object and sometimes it is too soon for the database to be ready. I init my DB on .run, instantly after the deviceready event has fired. But if i set the getAll query on my controller, an error is thrown due to the dbs not being ready. That can be “easily” solved by wrapping the query into a function, and fire that function when the user clicks over the input that will autocomplete the value with the object.

But the first solution leads me to the second problem.
After the first DB.init() on the deviceready event, i do a DB.update() where i update the whole table ( again ~1000 rows) with the updated information from the API. When that occurs, the update process can take up to… 8-13seconds to complete, and during that time, the database is busy, and the function that gets all the entries is not fired until the update process has finished. To solve that i’ve though in do a query before updating to have the information available at first, and while the user is using the “old” information, update the DB.

My third question is about storing that object.
I may use that object in several pages, and also in a ng-repeat filter (which fires several times) Maybe is not a good idea to query all the rows in a filter and in every page. Where should I store that object? into the rootsope for example? Or maybe I should do a service (factory), query the whole object and acces it?

sorry for the wall of text, but i’m sure that this awesome community will help me in these.
Thanks

I keep working on these and i wonder if anyone could help me with my issues.
I dont know if the text is well explained though.