How to use the rethinkdb.args function in rethinkdb

To help you get started, we’ve selected a few rethinkdb 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 hyperledger / sawtooth-core / extensions / mktplace / navigator / server / lib / mktplace / service / offer_service.js View on Github external
var secondaryFilters = [];
        // filter this first, as it is more specific than assets
        if (opts.filter.holdingId) {
            secondaryFilters.push(r.or(r.row('input')('id').eq(opts.filter.holdingId),
                                       r.row('output')('id').eq(opts.filter.holdingId)));
        } else if (opts.filter.assetId) {
            secondaryFilters.push(r.or(r.row('input')('asset').eq(opts.filter.assetId),
                                       r.row('output')('asset').eq(opts.filter.assetId)));
        } else if (opts.filter.inputAssetId) {
            secondaryFilters.push(r.row('input')('asset').eq(opts.filter.inputAssetId));
        } else if (opts.filter.outputAssetId) {
            secondaryFilters.push(r.row('output')('asset').eq(opts.filter.outputAssetId));
        }

        if (secondaryFilters.length > 0) {
            query = query.filter(r.and(r.args(secondaryFilters)));
        }

        if (opts.count) {
            return query.count();
        }

        if (opts.sort) {
            query = query.orderBy(opts.sort);
        }

        if (opts.limit && opts.page && opts.page > 0) {
            query = query.skip(opts.limit * opts.page);
        }

        if (opts.limit) {
            query = query.limit(opts.limit);
github outmoded / penseur / lib / criteria.js View on Github external
exports.select = function (criteria, table, options = {}) {

    if (criteria === null) {
        return table.raw;
    }

    // Optimize secondary index query

    if (Special.isSpecial(criteria) &&
        criteria.type === 'by') {

        return table.raw.getAll(RethinkDB.args(criteria.value), { index: criteria.flags.index });
    }

    // Construct query

    const base = (table._geo ? Geo.select(criteria, table) : table.raw);
    const filter = internals.compile(criteria, null, options);
    return (filter ? base.filter(filter) : base);
};
github hyperledger / sawtooth-core / extensions / mktplace / navigator / server / lib / mktplace / service / exchange_service.js View on Github external
TransactionStatuses.COMMITTED,
            TransactionStatuses.FAILED
        ];

        let ands = [
            queries.$in('Status', statuses),
            _update(r.row)('UpdateType').eq(UpdateTypes.EXCHANGE),
        ];

        if(optionalCreatorId) {
            ands.push(r.row('creator').eq(optionalCreatorId));
        } else {
            ands.push(_update(r.row)('OfferIdList').isEmpty().not());
        }

        let query = r.and(r.args(ands));

        var findOptions = {
            page: options.page,
            limit: options.limit,
            asArray: true,
        };

        // filter holding first, as it is more specific
        if(options.filter.holdingId) {
            findOptions.secondaryQuery = r.or(r.row('input')('id').eq(options.filter.holdingId),
                                              r.row('output')('id').eq(options.filter.holdingId),
                                              r.row('id').eq(options.filter.holdingId));
        } else if (options.filter.assetId) {
            findOptions.secondaryQuery = r.or(r.row('input')('asset').eq(options.filter.assetId),
                                              r.row('output')('asset').eq(options.filter.assetId),
                                              r.row('id').eq(options.filter.assetId));
github mikemintz / rethinkdb-websocket-server / src / ReqlTermExamples.js View on Github external
AUGUST: r.august,
  SEPTEMBER: r.september,
  OCTOBER: r.october,
  NOVEMBER: r.november,
  DECEMBER: r.december,
  LITERAL: r.literal({}),
  GROUP: r([]).group(''),
  SUM: r([]).sum(),
  AVG: r([]).avg(),
  MIN: r([]).min(),
  MAX: r([]).max(),
  SPLIT: r([]).split(),
  UNGROUP: r([]).ungroup(),
  RANDOM: r.random(),
  CHANGES: r([]).changes(),
  ARGS: r.args([]),
  BINARY: r.binary(new Buffer(0)),
  GEOJSON: r.geojson({}),
  TO_GEOJSON: r({}).toGeojson(),
  POINT: r.point(0, 0),
  LINE: r.line([], []),
  POLYGON: r.polygon([], [], []),
  DISTANCE: r.distance([], []),
  INTERSECTS: r.intersects(),
  INCLUDES: r([]).includes([]),
  CIRCLE: r.circle([], 0),
  GET_INTERSECTING: r([]).getIntersecting([]),
  FILL: r.line([], []).fill(),
  GET_NEAREST: r([]).getNearest([]),
  POLYGON_SUB: r.polygon([], [], []).polygonSub([]),
  MINVAL: r.minval,
  MAXVAL: r.maxval,
github outmoded / penseur / lib / table.js View on Github external
async _update(ids, changes, track) {

        try {
            const batch = Array.isArray(ids);
            ids = Id.normalize(ids, { allowArray: true });

            const postUnique = await Unique.reserve(this, changes, (batch ? true : ids));
            const wrapped = Modifier.wrap(changes, this);
            const opts = { returnChanges: !!postUnique };
            const query = (batch ? this.raw.getAll(RethinkDB.args(ids)) : this.raw.get(ids));
            const result = await this._db._run(query.replace(wrapped, opts), track);

            if (postUnique) {
                return postUnique(result.changes);
            }
        }
        catch (err) {
            throw internals.Table.error(err, track);
        }
    }
github ediket / nothinkdb / src / relations / belongsToMany.js View on Github external
function queryRelation(onePk, otherPk) {
    let query = relationTable.query();

    if (index) {
      if (_.isArray(otherPk)) {
        query = query.getAll(r.args(otherPk.map(otherPk => [onePk, otherPk])), { index });
      } else {
        query = query.getAll([onePk, otherPk], { index });
      }
    } else {
      query = query.getAll(onePk, { index: link1.left.field });

      if (_.isArray(otherPk)) {
        query = query.filter(row => r.expr(otherPk).contains(row(link2.left.field)));
      } else {
        query = query.filter({ [link2.left.field]: otherPk });
      }
    }

    return query;
  }
github ediket / nothinkdb / src / relations.js View on Github external
function queryRelation(onePk, otherPk) {
    let query = relationTable.query();

    if (index) {
      if (_.isArray(otherPk)) {
        query = query.getAll(r.args(otherPk.map(otherPk => [onePk, otherPk])), { index });
      } else {
        query = query.getAll([onePk, otherPk], { index });
      }
    } else {
      query = query.getAll(onePk, { index: link1.left.field });

      if (_.isArray(otherPk)) {
        query = query.filter(row => r.expr(otherPk).contains(row(link2.left.field)));
      } else {
        query = query.filter({ [link2.left.field]: otherPk });
      }
    }

    return query;
  }
github incrediblesound / nebulaDB / src / read.js View on Github external
r.connect(self.connection).then(function(conn){
      return r.table('data').getAll(r.args(ids), {index: index}).run(conn);
    }).then(function(cursor){
      cursor.toArray(cb);
github ediket / nothinkdb / src / relations / belongsToMany.js View on Github external
const relatedRowsQuery = targetIdsQuery.do(targetIds =>
      r.branch(
        targetIds.count().gt(0),
        link2.right.table.query()
          .getAll(r.args(targetIds), { index: link2.right.field }),
        r.expr([])
      )
    );
github outmoded / penseur / lib / table.js View on Github external
async get(ids, options = {}) {

        const track = { table: this.name, action: 'get', inputs: { ids, options } };

        try {
            const batch = Array.isArray(ids);
            ids = Id.normalize(ids, { allowArray: true });
            const query = (batch ? this.raw.getAll(RethinkDB.args(ids)) : this.raw.get(ids));
            const items = await this._db._run(this._refine(query, options), track);
            return this._read(items);
        }
        catch (err) {
            throw internals.Table.error(err, track);
        }
    }

rethinkdb

This package provides the JavaScript driver library for the RethinkDB database server for use in your node application.

Unknown
Latest version published 4 years ago

Package Health Score

61 / 100
Full package analysis