JSFiddle - React, Tailwind, and code Playground
by taylorbuley
JavaScript
/* Database name: InDBTest-001
* Database description: A test of unique index updating
*
* Store name: things
* Store indexes:
* - id (incrementing, unique)
* - hash (unique)
*
* Example row:
* { id, (int)
* , hash (string)
* , tokens (array) }
**/
/*
* Most code copy and pasted from https://github.com/editor/InDB/blob/master/indb.dev.js
* https://github.com/editor/InDB/blob/master/indbapp.dev.js
*/
// Install (create store and indexes)
// Add rows
// -> on success, update rows
var database_name = 'InDBTest-001'
, database_description = 'A test of unique index updating'
, indexes = {
'primary': {
'key': 'id'
, 'incrementing': true
, 'unique': true
}
, 'hash': true
, 'type': false
};
/* Begin test */
/* End test */
var InDBTest = new function() {
var version;
version = localStorage.getItem( database_name );
var db;
};
InDBTest.prototype.setVersion = function( version ) {
version = ( 'number' !== typeof version ) ? version : 0;
localStorage.setItem( database_name, version.toString() );
};
InDBTest.prototype.getVersion = function() {
localStorage.getItem( database_name );
};
InDBTest.prototype.install = function ( request ) {
var store = request.store;
this.createStore( { 'store': store, 'indexes': request.indexes, 'on_success': function() {
this.createIndexes( { 'store': store, 'indexes': request.indexes, 'on_success': function( result ) {
console.log( 'this.install() success' );
if( 'function' === typeof request.on_success ) {
request.on_success( result );
}
}, 'on_error': function( context ) {
console.log( 'this.install() error' );
if( 'function' === typeof request.on_error ) {
request.on_error( context );
}
} } );
...