Home › Forums › JavaScript › Using SQLite database with Javascript › Reply To: Using SQLite database with Javascript
July 22, 2014 at 6:29 am
#176158
Participant
Trying my luck with IndexedDB.
I can create a database and a table (object store) in it, get data from a json file (exported from the SQLite file), and load said data to a table. Rather simple and not really that slow (and it’s going to happen only on first install or specific upgrades so it’s not that bad :) )
But I just can’t figure out how to create multiple tables/object stores.
Only one of the object stores gets populated. It’s either the last one or the one which I don’t comment out.
Does anyone here have any experience with IndexedDB and can tell what am I doing wrong?
var request = window.indexedDB.open("myDB", 1);
request.onupgradeneeded = function (event) {
var db = event.target.result;
var alertAreasObjectStore, citiesDataObjectStore;
//object store 1
alertAreasObjectStore = db.createObjectStore("alertareas", { keyPath : "cityAlertId", unique: true });
alertAreasObjectStore.createIndex("alertAreasAlertAreaIndex", "alertArea", { });
alertAreasObjectStore.transaction.oncomplete = function(event) {
var obs = db.transaction("alertareas", "readwrite").objectStore("alertareas");
//loop - adding data
obs.put(...);
...
}
//object store 2
citiesDataObjectStore = db.createObjectStore("cities", { autoIncrement: true });
citiesDataObjectStore.createIndex("citiesAlertAreaIndex", "alertArea", { });
citiesDataObjectStore.transaction.oncomplete = function(event) {
var obs = db.transaction("cities", "readwrite").objectStore("cities");
//loop - adding data
obs.put(...);
...
}
}