Web Local Storage IndexedDB using Dexie.js
If you go to cnn.com and open the Chrome Browser Developer Tools. You can see that cnn.is storing data locally in an IndexedDB
Dexie.js is a wrapper over IndexedDB. It makes it easy to do CRUD. Note that all Dexie operations are asynchronous. Belows is a simple example of setting up a new "FriendsAndPetsDB" IndexedDB.
The ++id is the primary key. You can also version your database and let Dexie upgrade it.
var db = new Dexie("FriendsAndPetsDB");
db.version(1).stores({
friends: "++id,name,isCloseFriend",
pets: "++id,name,kind"
});
db.open();
db.friends.add({name: "Ingemar Bergman", isCloseFriend: 0});
db.pets.add({name: "Josephina", kind: "dog", fur: "too long right now"})
Comments