I'm having a problem to start with YDN-DB. I mean. I set up a scheme, I initialized the database, but when instantiating throws an error that says "ConstraintError: DOM Exception IDBDatabase 0". In the event handler "fail" gives me "Version change transaction was aborted in upgradeneeded event handler.". Reading about the problem I found with this link. Can not find the way to assign an event to trigger "onupgradeneeded" and I think that would solve the problem
I leave my piece of code:
var shopgroups_schema = {
name: 'shopgroups',
keyPath: 'id_shop_group',
autoIncrement: true,
indexes: [
{keyPath: 'id_shop_group'},
{keyPath: 'name'},
{keyPath: 'share_customer'},
{keyPath: 'share_order'},
{keyPath: 'share_stock'},
{keyPath: 'active'},
{keyPath: 'deleted'},
{keyPath: 'date_add'},
{keyPath: 'date_upd'},
{keyPath: 'date_upd'}
]
};
var shops_schema = {
name: 'shops',
keyPath: 'id_shop',
autoIncrement: true,
indexes: [
{keyPath: 'id_shop'},
{keyPath: 'id_shop_group'},
{keyPath: 'name'},
{keyPath: 'id_category'},
{keyPath: 'id_theme'},
{keyPath: 'active'},
{keyPath: 'deleted'},
{keyPath: 'date_add'},
{keyPath: 'date_upd'}
]
};
var schema = {
stores: [shopgroups_schema, shops_schema]
};
var schemaName = 'chollingApp4';
var db = new ydn.db.Storage(schemaName, schema);
db.addEventListener('error', function (event) {
var e = event.getError();
// common errors are AbortError, ConstraintError and UnknownError (possibliy for Quota exceed error).
// log error for debugging
console.log('connection failed with ' + e.name);
});
db.addEventListener('fail', function (event) {
var err = event.getError();
console.log(event);
console.log(err);
console.log('connection failed with ' + err.name + ' by ' + err.message);
db = null; // no operation can be placed to the database instance
});
db.addEventListener('ready', function (event) {
var is_updated = event.getVersion() != event.getOldVersion();
if (is_updated) {
console.log('database connected with new schema');
} else if (isNaN(event.getOldVersion())) {
console.log('new database created');
} else {
console.log('existing database connected');
}
// heavy database operations should start from this.
});
ConstraintError
in database opening suggest that schema could be a problem. I find you have index keyPath, date_upd
repeated.