indexeddb
by sonylnagale
JavaScript
IDBKeyRange.forPrefix = (prefix) => {
const successor = (key) => {
let len = key.length;
while (len > 0) {
const head = key.substring(0, len - 1);
const tail = key.charCodeAt(len - 1);
if (tail !== 0xFFFF) {
return head + String.fromCharCode(tail + 1);
}
key = head;
--len;
}
return UPPER_BOUND.STRING;
}
const upperKey = successor(prefix);
if (upperKey === undefined) {
return IDBKeyRange.lowerBound(prefix);
}
return IDBKeyRange.bound(prefix, upperKey, false, true);
};
/**
const IndexedDBAdapter = function (uuid) {
this.db;
this.queue = [];
console.log("IndexedDBAdapter init");
const SCHEMA_VERSION = 1;
let initialized = false;
// #region Initialize IndexedDB connection.
// Open the IndexedDB connection
const request = window.indexedDB.open("finsemble", SCHEMA_VERSION);
// Create the object store if necessary
request.onupgradeneeded = (event) => {
// Save the IDBDatabase interface
this.db = event.target.result;
// Create an objectStore for this database
const objectStore = this.db.createObjectStore("fsbl", { keyPath: "key" });
// Use transaction oncomplete to make sure the objectStore creation is
// finished before adding data into it.
objectStore.transaction.oncomplete = () => {
console.debug("IndexedDBAdapter object store created");
this.releaseQueue();
};
};
request.onsuccess = (event) => {
console.log("IndexedDBAdapter initialized successfully");
this.db = event.target.result;
this.releaseQueue();
};
request.onerror = (err) => {
console.error("IndexedDBAdapter DB connection initialization failed, Error: ", err);
};
// #endregion
// #endregion
/**
* Get the prefix used to filter keys for particular topics and key prefixes.
*
* @param {object} params
* @param {string} params.topic The topic
* @param {string} params.keyPrefix The key prefix (optional).
* @private
*/
this.getKeyPreface = (params) => {
const keyPrefix = "keyPrefix" in...