-
Notifications
You must be signed in to change notification settings - Fork 1
Database API
David Barnett edited this page Oct 17, 2016
·
4 revisions
To access the database a "connection" to the IndexedDB store needs to be opened first, otherwise all methods that access the database will return errors hinting at opening it before using them.
After a successful "connection" has been established you can call all the methods of the database, getAll, add, etc.
The "connection" is "terminated" when the addressbook object resulting from open() is destroyed
Addressbook.open(indexeddb).then((addrbook) => {
// calls to DB
}).catch((err) => {
// handle errors
}); // Get all the contacts
addrbook.getAll().then((contacts) => {
console.log(contacts);
});// Add contact
addrbook.add({name: "John", email: "cena@619.net", jcards: [...]}).then((contact) => {
console.log(contact);
});// Get all ids & names of contacts
addrbook.getNameAndId().then((contacts) => {
console.log(contacts);
});// Get all ids & names of contacts
addrbook.getById(1).then((contact) => {
console.log(contact);
});// Get all ids & names of contacts
addrbook.deleteById(1).then((_) => {
// _ is undefined
});