How to use the dexie.getByKeyPath function in dexie

To help you get started, we’ve selected a few dexie examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dfahlander / Dexie.js / addons / dexie-export-import / src / export.ts View on Github external
const filteredValues = filter ?
            values.filter(value => filter(tableName, value)) :
            values;

          const tsonValues = filteredValues.map(value => TSON.encapsulate(value));
          if (TSON.mustFinalize()) {
            await Dexie.waitFor(TSON.finalize(tsonValues));
          }

          let json = JSON.stringify(tsonValues, undefined, prettyJson ? 2 : undefined);
          if (prettyJson) json = json.split('\n').join('\n      ');

          // By generating a blob here, we give web platform the opportunity to store the contents
          // on disk and release RAM.
          slices.push(new Blob([json.substring(1, json.length - 1)]));
          lastKey = Dexie.getByKeyPath(values[values.length -1], primKey.keyPath as string);
        } else {
          const keys = await chunkedCollection.primaryKeys();
          let keyvals = keys.map((key, i) => [key, values[i]]);
          if (filter) keyvals = keyvals.filter(([key, value]) => filter(tableName, value, key));

          const tsonTuples = keyvals.map(tuple => TSON.encapsulate(tuple));
          if (TSON.mustFinalize()) {
            await Dexie.waitFor(TSON.finalize(tsonTuples));
          }

          let json = JSON.stringify(tsonTuples, undefined, prettyJson ? 2 : undefined);
          if (prettyJson) json = json.split('\n').join('\n      ');

          // By generating a blob here, we give web platform the opportunity to store the contents
          // on disk and release RAM.
          slices.push(new Blob([json.substring(1, json.length - 1)]));
github dfahlander / Dexie.js / addons / Dexie.Observable / src / Dexie.Observable.js View on Github external
// is being deleted. Since we cannot persist undefined we need to act
            // like those changes is setting the value to null instead.
            var modsWithoutUndefined = {};
            // As of current Dexie version (1.0.3) hook may be called even if it wouldnt really change.
            // Therefore we may do that kind of optimization here - to not add change entries if
            // there's nothing to change.
            var anythingChanged = false;
            var newObj = Dexie.deepClone(oldObj);
            for (var propPath in mods) {
                var mod = mods[propPath];
                if (typeof mod === 'undefined') {
                    Dexie.delByKeyPath(newObj, propPath);
                    modsWithoutUndefined[propPath] = null; // Null is as close we could come to deleting a property when not allowing undefined.
                    anythingChanged = true;
                } else {
                    var currentValue = Dexie.getByKeyPath(oldObj, propPath);
                    if (mod !== currentValue && JSON.stringify(mod) !== JSON.stringify(currentValue)) {
                        Dexie.setByKeyPath(newObj, propPath, mod);
                        modsWithoutUndefined[propPath] = mod;
                        anythingChanged = true;
                    }
                }
            }
            if (anythingChanged) {
                var change = {
                    source: trans.source || null, // If a "source" is marked on the transaction, store it. Useful for observers that want to ignore their own changes.
                    table: tableName,
                    key: primKey,
                    type: UPDATE,
                    mods: modsWithoutUndefined,
                    oldObj: oldObj,
                    obj: newObj
github LN-Zap / zap-desktop / renderer / store / dbVersions.js View on Github external
await tx.settings.toCollection().modify((setting, ref) => {
      const c = configMap.find(c => c.settingsKey === setting.key)
      if (c) {
        try {
          const defaultValue = Dexie.getByKeyPath(config, c.configPath)
          let value = Dexie.getByKeyPath(setting, c.settingsPath)
          // Apply value mapper if there is one.
          if (c.configMutator) {
            value = c.configMutator(value)
          }
          // If the value differes from the default, save it into the config.
          if (value && value !== defaultValue) {
            Dexie.setByKeyPath(newConfig, c.configPath, value)
          }
          // Finally, delete the old setting.
          delete ref.value
        } catch (e) {
          // If there was a problem migrating the old setting just delete the setting altogether.
          delete ref.value
        }
      }
github LN-Zap / zap-desktop / renderer / store / db.js View on Github external
await tx.settings.toCollection().modify((setting, ref) => {
      const c = configMap.find(c => c.settingsKey === setting.key)
      if (c) {
        try {
          const defaultValue = Dexie.getByKeyPath(config, c.configPath)
          let value = Dexie.getByKeyPath(setting, c.settingsPath)
          // Apply value mapper if there is one.
          if (c.configMutator) {
            value = c.configMutator(value)
          }
          // If the value differes from the default, save it into the config.
          if (value && value !== defaultValue) {
            Dexie.setByKeyPath(newConfig, c.configPath, value)
          }
          // Finally, delete the old setting.
          delete ref.value
        } catch (e) {
          // If there was a problem migrating the old setting just delete the setting altogether.
          delete ref.value
        }
      }
github LN-Zap / zap-desktop / renderer / store / db.js View on Github external
await tx.settings.toCollection().modify((setting, ref) => {
      const c = configMap.find(c => c.settingsKey === setting.key)
      if (c) {
        try {
          const defaultValue = Dexie.getByKeyPath(config, c.configPath)
          let value = Dexie.getByKeyPath(setting, c.settingsPath)
          // Apply value mapper if there is one.
          if (c.configMutator) {
            value = c.configMutator(value)
          }
          // If the value differes from the default, save it into the config.
          if (value && value !== defaultValue) {
            Dexie.setByKeyPath(newConfig, c.configPath, value)
          }
          // Finally, delete the old setting.
          delete ref.value
        } catch (e) {
          // If there was a problem migrating the old setting just delete the setting altogether.
          delete ref.value
        }
      }
    })
github dfahlander / Dexie.js / addons / Dexie.Observable / src / Dexie.Observable.js View on Github external
// is being deleted. Since we cannot persist undefined we need to act
            // like those changes is setting the value to null instead.
            var modsWithoutUndefined = {};
            // As of current Dexie version (1.0.3) hook may be called even if it wouldnt really change.
            // Therefore we may do that kind of optimization here - to not add change entries if
            // there's nothing to change.
            var anythingChanged = false;
            var newObj = Dexie.deepClone(oldObj);
            for (var propPath in mods) {
                var mod = mods[propPath];
                if (typeof mod === 'undefined') {
                    Dexie.delByKeyPath(newObj, propPath);
                    modsWithoutUndefined[propPath] = null; // Null is as close we could come to deleting a property when not allowing undefined.
                    anythingChanged = true;
                } else {
                    var currentValue = Dexie.getByKeyPath(oldObj, propPath);
                    if (mod !== currentValue && JSON.stringify(mod) !== JSON.stringify(currentValue)) {
                        Dexie.setByKeyPath(newObj, propPath, mod);
                        modsWithoutUndefined[propPath] = mod;
                        anythingChanged = true;
                    }
                }
            }
            if (anythingChanged) {
                var change = {
                    source: trans.source || null, // If a "source" is marked on the transaction, store it. Useful for observers that want to ignore their own changes.
                    table: tableName,
                    key: primKey,
                    type: UPDATE,
                    mods: modsWithoutUndefined,
                    oldObj: oldObj,
                    obj: newObj
github dfahlander / Dexie.js / addons / dexie-export-import / src / tson.ts View on Github external
TSON.finalize = async (items?: any[]) => {
  const allChunks = await readBlobAsync(new Blob(blobsToAwait), 'binary');
  if (items) {
    for (const item of items) {
      // Manually go through all "blob" types in the result
      // and lookup the data slice they point at.
      if (item.$types) {
        let types = item.$types;
        const arrayType = types.$;
        if (arrayType) types = types.$;
        for (let keyPath in types) {
          const typeName = types[keyPath];
          const typeSpec = TSON.types[typeName];
          if (typeSpec && typeSpec.finalize) {
            const b = Dexie.getByKeyPath(item, arrayType ? "$." + keyPath : keyPath);
            typeSpec.finalize(b, allChunks.slice(b.start, b.end));
          }
        }
      }
    }
  }
  // Free up memory
  blobsToAwait = [];
}
github LN-Zap / zap-desktop / renderer / store / db.js View on Github external
Node.prototype.getCurrentAddress = function(type) {
    return Dexie.getByKeyPath(this, `addresses.${type}`)
  }
github LN-Zap / zap-desktop / app / store / db.js View on Github external
Node.prototype.getCurrentAddress = function(type) {
    return Dexie.getByKeyPath(this, `addresses.${type}`)
  }