How to use pouchdb-selector-core - 10 common examples

To help you get started, we’ve selected a few pouchdb-selector-core 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-find / src / adapters / local / abstract-mapper.js View on Github external
function createDeepSingleMapper(field, emit) {
  var parsedField = parseField(field);
  return function (doc) {
    var value = doc;
    for (var i = 0, len = parsedField.length; i < len; i++) {
      var key = parsedField[i];
      value = value[key];
      if (typeof value === 'undefined') {
        return; // do nothing
      }
    }
    emit(value);
  };
}
github pouchdb / pouchdb / packages / node_modules / pouchdb-find / src / adapters / local / abstract-mapper.js View on Github external
return function (doc) {
    var toEmit = [];
    for (var i = 0, iLen = fields.length; i < iLen; i++) {
      var parsedField = parseField(fields[i]);
      var value = doc;
      for (var j = 0, jLen = parsedField.length; j < jLen; j++) {
        var key = parsedField[j];
        value = value[key];
        if (typeof value === 'undefined') {
          return; // don't emit
        }
      }
      toEmit.push(value);
    }
    emit(toEmit);
  };
}
github pouchdb / pouchdb / packages / node_modules / pouchdb-find / src / adapters / local / find / query-planner.js View on Github external
function checkFieldsLogicallySound(indexFields, selector) {
  var firstField = indexFields[0];
  var matcher = selector[firstField];

  if (typeof matcher === 'undefined') {
    /* istanbul ignore next */
    return true;
  }

  var isInvalidNe = Object.keys(matcher).length === 1 &&
    getKey(matcher) === '$ne';

  return !isInvalidNe;
}
github pouchdb / pouchdb / packages / node_modules / pouchdb-find / src / adapters / local / find / query-planner.js View on Github external
function getSingleFieldCoreQueryPlan(selector, index) {
  var field = getKey(index.def.fields[0]);
  //ignoring this because the test to exercise the branch is skipped at the moment
  /* istanbul ignore next */
  var matcher = selector[field] || {};
  var inMemoryFields = [];

  var userOperators = Object.keys(matcher);

  var combinedOpts;

  userOperators.forEach(function (userOperator) {

    if (isNonLogicalMatcher(userOperator)) {
      inMemoryFields.push(field);
    }

    var userValue = matcher[userOperator];
github pubkey / rxdb / src / query-change-detector.ts View on Github external
export function _resortDocData(
    queryChangeDetector: QueryChangeDetector,
    resultsData: any[]
) {
    const sortOptions = _getSortOptions(queryChangeDetector);
    const rows = resultsData.map(doc => {
        return {
            doc: queryChangeDetector.query.collection.schema.swapPrimaryToId(doc)
        };
    });
    const inMemoryFields = Object.keys(queryChangeDetector.query.toJSON().selector);

    // TODO use createFieldSorter
    const sortedRows: any[] = filterInMemoryFields(
        rows, {
            selector: queryChangeDetector.query.massageSelector,
            sort: sortOptions
        },
        inMemoryFields
    );
    const sortedDocs = sortedRows
        .map(row => row.doc)
        .map(doc => queryChangeDetector.query.collection.schema.swapIdToPrimary(doc));
    return sortedDocs;
}
github pouchdb / pouchdb / packages / node_modules / pouchdb-find / src / adapters / local / find / index.js View on Github external
}).then(function (res) {
      if (opts.inclusive_start === false) {
        // may have to manually filter the first one,
        // since couchdb has no true inclusive_start option
        res.rows = filterInclusiveStart(res.rows, opts.startkey, indexToUse);
      }

      if (queryPlan.inMemoryFields.length) {
        // need to filter some stuff in-memory
        res.rows = filterInMemoryFields(res.rows, requestDef, queryPlan.inMemoryFields);
      }

      var resp = {
        docs: res.rows.map(function (row) {
          var doc = row.doc;
          if (requestDef.fields) {
            return pick(doc, requestDef.fields);
          }
          return doc;
        })
      };

      if (indexToUse.defaultUsed) {
        resp.warning = 'no matching index found, create an index to optimize query time';
      }
github pubkey / rxdb / dist / es / query-change-detector.js View on Github external
export function _resortDocData(queryChangeDetector, resultsData) {
  var sortOptions = _getSortOptions(queryChangeDetector);

  var rows = resultsData.map(function (doc) {
    return {
      doc: queryChangeDetector.query.collection.schema.swapPrimaryToId(doc)
    };
  });
  var inMemoryFields = Object.keys(queryChangeDetector.query.toJSON().selector); // TODO use createFieldSorter

  var sortedRows = filterInMemoryFields(rows, {
    selector: queryChangeDetector.query.massageSelector,
    sort: sortOptions
  }, inMemoryFields);
  var sortedDocs = sortedRows.map(function (row) {
    return row.doc;
  }).map(function (doc) {
    return queryChangeDetector.query.collection.schema.swapIdToPrimary(doc);
  });
  return sortedDocs;
}
/**
github pubkey / rxdb / dist / es / query-change-detector.js View on Github external
export function _isSortedBefore(queryChangeDetector, docDataLeft, docDataRight) {
  var sortOptions = _getSortOptions(queryChangeDetector);

  var inMemoryFields = Object.keys(queryChangeDetector.query.toJSON().selector);
  var swappedLeft = queryChangeDetector.query.collection.schema.swapPrimaryToId(docDataLeft);
  var swappedRight = queryChangeDetector.query.collection.schema.swapPrimaryToId(docDataRight);
  var rows = [swappedLeft, swappedRight].map(function (doc) {
    return {
      id: doc._id,
      doc: doc
    };
  }); // TODO use createFieldSorter

  var sortedRows = filterInMemoryFields(rows, {
    selector: queryChangeDetector.query.massageSelector,
    sort: sortOptions
  }, inMemoryFields);
  return sortedRows[0].id === swappedLeft._id;
}
/**
github pubkey / rxdb / src / query-change-detector.ts View on Github external
docDataRight: any
): boolean {
    const sortOptions = _getSortOptions(queryChangeDetector);
    const inMemoryFields = Object.keys(queryChangeDetector.query.toJSON().selector);
    const swappedLeft = queryChangeDetector.query.collection.schema.swapPrimaryToId(docDataLeft);
    const swappedRight = queryChangeDetector.query.collection.schema.swapPrimaryToId(docDataRight);
    const rows = [
        swappedLeft,
        swappedRight
    ].map(doc => ({
        id: doc._id,
        doc
    }));

    // TODO use createFieldSorter
    const sortedRows = filterInMemoryFields(
        rows, {
            selector: queryChangeDetector.query.massageSelector,
            sort: sortOptions
        },
        inMemoryFields
    );
    return sortedRows[0].id === swappedLeft._id;
}
github pouchdb / pouchdb / packages / node_modules / pouchdb-find / src / adapters / local / find / index.js View on Github external
var opts = Object.assign({
      include_docs: true,
      reduce: false
    }, queryPlan.queryOpts);

    if ('startkey' in opts && 'endkey' in opts &&
        collate(opts.startkey, opts.endkey) > 0) {
      // can't possibly return any results, startkey > endkey
      /* istanbul ignore next */
      return {docs: []};
    }

    var isDescending = requestDef.sort &&
      typeof requestDef.sort[0] !== 'string' &&
      getValue(requestDef.sort[0]) === 'desc';

    if (isDescending) {
      // either all descending or all ascending
      opts.descending = true;
      opts = reverseOptions(opts);
    }

    if (!queryPlan.inMemoryFields.length) {
      // no in-memory filtering necessary, so we can let the
      // database do the limit/skip for us
      if ('limit' in requestDef) {
        opts.limit = requestDef.limit;
      }
      if ('skip' in requestDef) {
        opts.skip = requestDef.skip;
      }