How to use pouchdb-json - 10 common examples

To help you get started, we’ve selected a few pouchdb-json 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 pouchdb / pouchdb / packages / node_modules / pouchdb-adapter-idb / src / utils.js View on Github external
function encodeMetadata(metadata, winningRev, deleted) {
  return {
    data: safeJsonStringify(metadata),
    winningRev: winningRev,
    deletedOrLocal: deleted ? '1' : '0',
    seq: metadata.seq, // highest seq for this doc
    id: metadata.id
  };
}
github stockulus / pouchdb-react-native / packages / pouchdb-adapter-asyncstorage / src / asyncstorage_core.js View on Github external
const parseValue = value => {
  if (typeof value === 'string') return safeJsonParse(value)
  return null
}
github pouchdb / pouchdb / packages / node_modules / pouchdb-adapter-websql-core / src / bulkDocs.js View on Github external
' WHERE id = ?', [id], function (tx, result) {
        if (result.rows.length) {
          var metadata = safeJsonParse(result.rows.item(0).json);
          fetchedDocs.set(id, metadata);
        }
        checkDone();
      });
    });
github pouchdb / pouchdb / packages / node_modules / pouchdb-adapter-websql-core / src / index.js View on Github external
tx.executeSql(sql, [docId], function (tx, result) {
        if (!result.rows.length) {
          callback(createError(MISSING_DOC));
        } else {
          var data = safeJsonParse(result.rows.item(0).metadata);
          callback(null, data.rev_tree);
        }
      });
    });
github pouchdb / pouchdb / packages / node_modules / pouchdb-adapter-idb / src / utils.js View on Github external
function decodeMetadata(storedObject) {
  if (!storedObject) {
    return null;
  }
  var metadata = safeJsonParse(storedObject.data);
  metadata.winningRev = storedObject.winningRev;
  metadata.deleted = storedObject.deletedOrLocal === '1';
  metadata.seq = storedObject.seq;
  return metadata;
}
github pouchdb / pouchdb / packages / node_modules / pouchdb-adapter-websql-core / src / index.js View on Github external
tx.executeSql(sql, sqlArgs, function (a, results) {
      if (!results.rows.length) {
        var missingErr = createError(MISSING_DOC, 'missing');
        return finish(missingErr);
      }
      var item = results.rows.item(0);
      metadata = safeJsonParse(item.metadata);
      if (item.deleted && !opts.rev) {
        var deletedErr = createError(MISSING_DOC, 'deleted');
        return finish(deletedErr);
      }
      doc = unstringifyDoc(item.data, metadata.id, item.rev);
      finish();
    });
  };
github pouchdb / pouchdb / packages / node_modules / pouchdb-adapter-websql-core / src / index.js View on Github external
tx.executeSql(sql, sqlArgs, function (tx, result) {
          function reportChange(change) {
            return function () {
              opts.onChange(change);
            };
          }
          for (var i = 0, l = result.rows.length; i < l; i++) {
            var item = result.rows.item(i);
            var metadata = safeJsonParse(item.metadata);
            lastSeq = item.maxSeq;

            var doc = unstringifyDoc(item.winningDoc, metadata.id,
              item.winningRev);
            var change = opts.processChange(doc, metadata, opts);
            change.seq = item.maxSeq;

            var filtered = filter(change);
            if (typeof filtered === 'object') {
              return opts.complete(filtered);
            }

            if (filtered) {
              numResults++;
              if (opts.return_docs) {
                results.push(change);
github pouchdb / pouchdb / packages / node_modules / pouchdb-adapter-websql-core / src / index.js View on Github external
tx.executeSql(sql, sqlArgs, function (tx, result) {
        for (var i = 0, l = result.rows.length; i < l; i++) {
          var item = result.rows.item(i);
          var metadata = safeJsonParse(item.metadata);
          var id = metadata.id;
          var data = unstringifyDoc(item.data, id, item.rev);
          var winningRev = data._rev;
          var doc = {
            id: id,
            key: id,
            value: {rev: winningRev}
          };
          if (opts.include_docs) {
            doc.doc = data;
            doc.doc._rev = winningRev;
            if (opts.conflicts) {
              var conflicts = collectConflicts(metadata);
              if (conflicts.length) {
                doc.doc._conflicts = conflicts;
              }
github pouchdb / pouchdb / packages / node_modules / pouchdb-adapter-websql-core / src / index.js View on Github external
tx.executeSql(sql, [docId], function (tx, result) {
        var metadata = safeJsonParse(result.rows.item(0).metadata);
        traverseRevTree(metadata.rev_tree, function (isLeaf, pos,
                                                           revHash, ctx, opts) {
          var rev = pos + '-' + revHash;
          if (revs.indexOf(rev) !== -1) {
            opts.status = 'missing';
          }
        });

        var sql = 'UPDATE ' + DOC_STORE + ' SET json = ? WHERE id = ?';
        tx.executeSql(sql, [safeJsonStringify(metadata), docId]);
      });
github stockulus / pouchdb-react-native / packages / pouchdb-adapter-asyncstorage / src / asyncstorage_core.js View on Github external
const stringifyValue = value => {
  if (value === null) return ''
  if (value === undefined) return ''

  return safeJsonStringify(value)
}

pouchdb-json

PouchDB utilities for safely stringifying and parsing JSON.

Apache-2.0
Latest version published 6 months ago

Package Health Score

85 / 100
Full package analysis

Similar packages