-
Notifications
You must be signed in to change notification settings - Fork 3
Javascript
nimda edited this page May 7, 2022
·
3 revisions
const db = new IndexedDB.Database({
version: 2,
name: 'boo',
tables: [
{
name: 'myNewTable',
primaryKey: {
name: 'id',
autoIncrement: true,
unique: true,
},
initData: [],
indexes: {
roomId: {unique: false},
},
},
],
});
db.connect()
.then(() => {
// add new record
const model = db.useModel('myNewTable');
model
.insert({
roomId: 16,
roomName: 'My room name',
comment: 'This room is awesome',
})
.then(function (data) {
console.info('Yay. data has been saved!', {data});
})
.catch(function (error) {
console.error(error);
});
// Get all results from DB
model.selectAll().then(function (results) {
console.log(...results);
});
})
.catch(console.error);