Brett
Brett

Reputation: 1781

how to load breeze entity from local storage websql

I don't have access to an OData provider just a simple REST api with json and I need to store the data locally (on the mobile device websql) in different tables reflecting the backend model. Following the Edmunds example I have got the entity and the relationships working from the REST api. How can I make it work the same way from the data stored locally. I would like to fetch the data from the local DB and recreate my entities, any advice would be appreciated thanks.

Upvotes: 0

Views: 542

Answers (1)

Jay Traband
Jay Traband

Reputation: 17052

After you have queried the data thru the REST api, just export the EntityManager to local storage. Something like this

     var changesExport = myEntityManager.exportEntities();

     ok(window.localStorage, "this browser supports local storage");
     var stashName = "arbitrary name for storage area"";

     window.localStorage.setItem(stashName, changesExport);

This data can later be reimported into any existing EntityManager, and then queried locally by simply reimporting the data.

     importedData = window.localStorage.getItem(stashName);

     anotherEntityManager.importEntities(importedData);

Upvotes: 1

Related Questions