Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
initialize() {
// Set our defaults
const dbName = '/user_data';
const objectStoreName = 'FILE_DATA';
const cartDataName = picoDeployConfig.dbWatcher.cartDataName;
const cartDataKey = `/user_data/cdata/${cartDataName}.p8d.txt`;
this.cartDataKey = cartDataKey;
// pico 8 idb version is 21
const dbPromise = idb.open(dbName, 21, upgradeDB => {
//TODO: Handle Upgrade
console.log('Pico-db: Upgrading db by creating the object store for pico-8', upgradeDB);
// Create the object store
upgradeDB.createObjectStore(objectStoreName);
});
// Only need the get functionality of idbKeyval
// https://github.com/jakearchibald/idb
this.idbKeyval = {
get(key) {
return dbPromise.then(db => {
if(db) {
return db.transaction(objectStoreName)
.objectStore(objectStoreName).get(key);
}
const DB_NAME = 'YouVersion'
const VERSION = 1
// schemas
// database functions
const createStore = (upgradeDB, storeName, options) => {
if (!upgradeDB.objectStoreNames.contains(storeName)) {
upgradeDB.createObjectStore(storeName, options);
}
}
const dbPromise = idb.open(DB_NAME, VERSION, (upgradeDB) => {
// upgradeCallback is called if version is greater than the version last opened
createStore(upgradeDB, 'plans', { keyPath: 'id' })
})
const database = {
get({ storeName, key }) {
return dbPromise.then((db) => {
return db.transaction(storeName)
.objectStore(storeName).get(key)
})
},
set({ storeName, key = null, val }) {
return dbPromise.then((db) => {
const tx = db.transaction(storeName, 'readwrite')
tx.objectStore(storeName).put(val, key)
return tx.complete
export function getDb() {
return idb.open('FEGrocerDB', 3, upgrade => {
switch(upgrade.oldVersion) {
case 0: // New database
upgrade.createObjectStore('grocery-items', {keyPath: 'id'});
case 1: // Upgrade from v1 to v2
upgrade.createObjectStore('cart', { keyPath: 'groceryItem.id'})
case 2: // Upgrade from v3 to v3
let tx = upgrade.transaction;
let giStore = tx.objectStore('grocery-items');
giStore.createIndex('categoryIndex', 'category');
}
});
}
/* eslint-enable no-case-declarations */
_getDb() {
if (this._dbPromise) {
return this._dbPromise;
}
this._dbPromise = idb.open(this._name, this._version, (upgradeDB) => {
upgradeDB.createObjectStore(this._storeName);
})
.then((db) => {
return db;
});
return this._dbPromise;
}
async getDB({cacheName} = {}) {
isType({cacheName}, 'string');
const idbId = `${idbName}-${cacheName}`;
if (!this._dbs.has(idbId)) {
const openDb = await idb.open(idbId, idbVersion, (upgradeDB) => {
const objectStore = upgradeDB.createObjectStore(cacheName,
{keyPath: urlPropertyName});
objectStore.createIndex(timestampPropertyName, timestampPropertyName,
{unique: false});
});
this._dbs.set(idbId, openDb);
}
return this._dbs.get(idbId);
}
public openDb = async (data: IDbStore, instanceWrapper: IDotNetInstanceWrapper): Promise => {
const dbStore = data;
//just a test for the moment
this.dotnetCallback = (message: string) => {
instanceWrapper.instance.invokeMethod(instanceWrapper.methodName, message);
}
if (this.dbInstance) {
await this.dbInstance.close();
}
this.dbInstance = await idb.open(dbStore.dbName, dbStore.version, upgradeDB => {
this.upgradeDatabase(upgradeDB, dbStore);
});
return `IndexedDB ${data.dbName} opened`;
}
_open() {
return this._dbPromise = idb.open(this._id, 1, upgradeDB => {
upgradeDB.createObjectStore(CART_STORE, {autoIncrement: true});
});
}
function _openDatabase() {
return idb.open(DATABASE_NAME, DATABASE_VERSION,
upgradeDb => {
if (!upgradeDb.objectStoreNames.contains(STATE_STORE)) {
upgradeDb.createObjectStore(STATE_STORE, {keyPath: 'key'});
}
if (!upgradeDb.objectStoreNames.contains(MESSAGE_CACHE_STORE)) {
const messageCacheStore = upgradeDb.createObjectStore(MESSAGE_CACHE_STORE, {keyPath: 'key'});
messageCacheStore.createIndex('userId', 'userId', {unique: false});
}
if (!upgradeDb.objectStoreNames.contains(NEW_MESSAGE_STORE)) {
upgradeDb.createObjectStore(NEW_MESSAGE_STORE, {keyPath: 'key'});
}
});
}