How to use the rethinkdb.and 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 outmoded / penseur / lib / db.js View on Github external
const primaryKey = tableOptions.primary || 'id';
            const existingConfig = existing[name];
            let drop = false;
            if (existingConfig &&
                existingConfig.primary_key !== primaryKey) {

                drop = RethinkDB.db(this.name).tableDrop(name);
            }

            // Create new table

            if (!existingConfig ||
                drop) {

                const create = RethinkDB.db(this.name).tableCreate(name, { primaryKey });
                const change = (drop ? RethinkDB.and(drop, create) : create);
                await change.run(this._connection);
            }
            else {

                // Reuse existing table

                if (tableOptions.purge !== false) {              // Defaults to true
                    await this.tables[name].empty();
                }

                if (tableOptions.secondary !== false) {         // false means leave as-is (vs null or empty array which drops existing)
                    for (let j = 0; j < existingConfig.indexes.length; ++j) {
                        const index = existingConfig.indexes[j];
                        await RethinkDB.db(this.name).table(name).indexDrop(index).run(this._connection);
                    }
                }
github davidgljay / nametag / horizon / server / src / endpoint / update.js View on Github external
collection.table.get(new_row('id')).replace((old_row) =>
              r.branch(// The row may have been deleted between the get and now
                       old_row.eq(null),
                       r.error(writes.missing_msg),

                       // The row may have been changed between the get and now
                       r.and(new_row.hasFields(hz_v),
                             old_row(hz_v).default(-1).ne(new_row(hz_v))),
                       r.error(writes.invalidated_msg),

                       // Otherwise we can safely update the row and increment the version
                       writes.apply_version(old_row.merge(new_row), old_row(hz_v).default(-1).add(1))),
              { returnChanges: 'always' }))
github rethinkdb / horizon / server / src / endpoint / remove.js View on Github external
collection.table.get(info('id')).replace((row) =>
              r.branch(// The row may have been deleted between the get and now
                       row.eq(null),
                       null,

                       // The row may have been changed between the get and now
                       r.and(info.hasFields(hz_v),
                             row(hz_v).default(-1).ne(info(hz_v))),
                       r.error(writes.invalidated_msg),

                       // Otherwise, we can safely remove the row
                       null),
github rethinkdb / horizon / server / src / endpoint / update.js View on Github external
collection.table.get(new_row('id')).replace((old_row) =>
              r.branch(// The row may have been deleted between the get and now
                       old_row.eq(null),
                       r.error(writes.missing_msg),

                       // The row may have been changed between the get and now
                       r.and(new_row.hasFields(hz_v),
                             old_row(hz_v).default(-1).ne(new_row(hz_v))),
                       r.error(writes.invalidated_msg),

                       // Otherwise we can safely update the row and increment the version
                       writes.apply_version(old_row.merge(new_row), old_row(hz_v).default(-1).add(1))),
              { returnChanges: 'always' }))
github t1msh / node-oauth20-provider / test / server / model / rethinkdb / oauth2 / accessToken.js View on Github external
module.exports.fetchByUserIdClientId = function(userId, clientId, cb) {
    var where = RethinkDb.and(
        RethinkDb.row('userId').eq(userId),
        RethinkDb.row('clientId').eq(clientId),
        RethinkDb.row('ttl').gt(new Date().getTime())
    );
    connection.acquire(function(err, conn) {
        if (err) cb(err);
        else {
            RethinkDb.table(TABLE).filter(where).orderBy(RethinkDb.desc('ttl')).limit(1).run(conn, function(err, cursor) {
                if (err) cb(err);
                else cursor.next(cb);
            });
        }
    });
};
github hyperledger / sawtooth-core / extensions / mktplace / navigator / server / lib / mktplace / service / participant_service.js View on Github external
.then(party => {
                if (!party) {
                    return undefined;
                }

                var accountsPromise;
                if(_.isEmpty(party.accounts)) {
                    accountsPromise = transaction.findExact(
                        r.and(r.row('Updates').nth(0)('UpdateType').eq(UpdateTypes.REGISTER_ACCOUNT),
                              r.row.hasFields('creator'),
                              r.row('creator').eq(id)),
                        {asArray: true})
                    .then(txns => _.map(txns, t => ({
                        id: t.id,
                        name: t.Updates[0].Name,
                        description: t.Updates[0].Description,
                        pending: true
                    })));
                } else {
                    accountsPromise = Promise.resolve(party.accounts);
                }

                return accountsPromise.then(accounts => {
                    party.account = _.first(accounts);
                    return _.omit(party, 'address', 'accounts');
github hyperledger / sawtooth-core / extensions / mktplace / navigator / server / lib / mktplace / service / offer_service.js View on Github external
availableOffers: (participantId, options) =>
        _doFetch(
                participantId,
                r.or(r.row('execution').eq('Any'),
                     r.row('execution').eq('ExecuteOnce'),
                     r.and(r.row('execution').eq('ExecuteOncePerParticipant'),
                           r.row('execution-state')('ParticipantList').contains(participantId).not())),
                options),
github hyperledger / sawtooth-core / extensions / mktplace / navigator / server / lib / mktplace / service / participant_service.js View on Github external
.then(participant => {
                if(participant) {
                    return participant;
                }

                return transaction.findExact(
                        r.and(r.row('Updates').nth(0)('UpdateType').eq(UpdateTypes.REGISTER_PARTICIPANT),
                              r.row('Status').eq(TransactionStatuses.PENDING),
                              r.row('address').eq(address)),
                        {asArray: true})
                    .then(txns => _.map(txns, (t) => ({
                                                id: t.id,
                                                displayName: t.Updates[0].Name,
                                                name: t.Updates[0].Name,
                                                description: t.Updates[0].Description,
                                                pending: true
                                              })))
                    .then(_.first);
            }),
github davidgljay / nametag / horizon / server / src / metadata / metadata.js View on Github external
          .filter((row) => r.and(row('db').eq(this._db),
                                 row('name').match('^hz_').not()))
          .map((row) => ({
github hyperledger / sawtooth-core / extensions / mktplace / navigator / server / lib / mktplace / service / offer_service.js View on Github external
                  .filter(t => r.and(t('Status').eq(TransactionStatuses.PENDING),
                                     t('creator').eq(participantId),
                                     _update(t)('UpdateType').eq(UpdateTypes.EXCHANGE),
                                     _update(t)('OfferIdList').contains(offer('id'))))
                  .count().gt(0);

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