function dbAdd(table, data){
let openRequest = indexedDB.open('mydb', 1);
openRequest.onsuccess = function() {
let db = openRequest.result;
let transaction = db.transaction(table, 'readwrite');
let objectStore = transaction.objectStore(table);
let request = objectStore.add(data); // добавление с автоинкрементным ключом
request.onsuccess = function(event) {
console.log('Record added');
};
db.close();
};
}
function dbput(table, data){
let openRequest = indexedDB.open('mydb', 1);
openRequest.onsuccess = function() {
let db = openRequest.result;
let transaction = db.transaction(table, 'readwrite');
let objectStore = transaction.objectStore(table);
let key = data.id; // явный ключ
let request = objectStore.put(data, key); // добавление с явным ключом
request.onsuccess = function(event) {
console.log('Record added/updated');
};
db.close();
};
}