How to use the rethinkdb.expr 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 davidgljay / nametag / horizon / server / src / endpoint / remove.js View on Github external
(rows) => // write to database, all valid rows
      r.expr(rows).do((row_data) =>
        row_data.forEach((info) =>
          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),

              { returnChanges: 'always' }))
          // Pretend like we deleted rows that didn't exist
github rethinkdb / horizon / cli / src / set-schema.js View on Github external
r.branch(old_row.eq(null),
                     group,
                     old_row.merge(literal_group)))
          .run(conn).then((res) => {
            if (res.errors) {
              throw new Error(`Failed to update group: ${res.first_error}`);
            }
          });
      }));
    } else {
      // Replace and remove groups
      const groups_obj = { };
      schema.groups.forEach((g) => { groups_obj[g.id] = g; });

      return Promise.all([
        r.expr(groups_obj).do((groups) =>
          r.db(internal_db).table('groups')
            .replace((old_row) =>
              r.branch(groups.hasFields(old_row('id')),
                       old_row,
                       null))
          ).run(conn).then((res) => {
            if (res.errors) {
              throw new Error(`Failed to write groups: ${res.first_error}`);
            }
          }),
        r.db(internal_db).table('groups')
          .insert(schema.groups, { conflict: 'replace' })
          .run(conn).then((res) => {
            if (res.errors) {
              throw new Error(`Failed to write groups: ${res.first_error}`);
            }
github rethinkdb / horizon / server / src / endpoint / upsert.js View on Github external
(rows) => // write to database, all valid rows
      r.expr(rows)
        .forEach((new_row) =>
          r.branch(new_row.hasFields('id'),
                   collection.table.get(new_row('id')).replace((old_row) =>
                       r.branch(
                         old_row.eq(null),
                         r.branch(
                           // Error if we were expecting the row to exist
                           new_row.hasFields(hz_v),
                           r.error(writes.invalidated_msg),

                           // Otherwise, insert the row
                           writes.apply_version(new_row, 0)
                         ),
                         r.branch(
                           // The row may have changed from the expected version
                           r.and(new_row.hasFields(hz_v),
github reindexio / reindex-api / db / rethinkdb / queries / migrationQueries.js View on Github external
function deleteTypesData(conn, commands) {
  const names = commands.map((command) => command.type.name);
  return RethinkDB.expr(names).forEach((name) => (
    RethinkDB.tableDrop(name)
  )).run(conn);
}
github davidgljay / nametag / horizon / server / src / auth.js View on Github external
auth_key (provider, info) {
    if (info === null || Array.isArray(info) || typeof info !== 'object') {
      return [ provider, info ]
    } else {
      return [ provider, r.expr(info).toJSON() ]
    }
  }
github ediket / nothinkdb / src / relations.js View on Github external
function query(row, options = {}) {
    const {
      apply = query => query,
    } = parseOptions(options);

    let query = left.table.query();
    query = query.getAll(row(right.field), { index: left.field });
    query = apply(query);

    return r.branch(
      row(right.field),
      query,
      r.expr([]),
    );
  }
github pedromsilvapt / unicast / src / Controllers / ApiControllers / MediaControllers / MediaController.ts View on Github external
} ).filter( ( doc : any ) => {
                    if ( included.length > 0 && excluded.length > 0 ) {
                        return doc( "collections" ).setIntersection( r.expr( included ) ).isEmpty().not().and(
                            doc( "collections" ).setIntersection( r.expr( excluded ) ).isEmpty()
                        );
                    } else if ( excluded.length > 0 ) {
                        return doc( "collections" ).setIntersection( r.expr( excluded ) ).isEmpty();
                    } else if ( included.length > 0 ) {
                        return doc( "collections" ).setIntersection( r.expr( included ) ).isEmpty().not();
                    }
                } );
            }
github jmdobry / RequelPro / src / RequelPro / models / table.js View on Github external
value = parseInt(value, 10);
        }
        if (operator === '==') {
          clause = clause.eq(value);
        } else if (operator === '!=') {
          clause = clause.ne(value);
        } else if (operator === '>') {
          clause = clause.gt(value);
        } else if (operator === '<') {
          clause = clause.lt(value);
        } else if (operator === '>=') {
          clause = clause.ge(value);
        } else if (operator === '<=') {
          clause = clause.le(value);
        } else if (operator === 'in') {
          clause = r.expr(value).contains(clause);
        } else if (operator === 'is null') {
          clause = clause.eq(null);
        }
        rql = rql.filter(clause);
      }
      if (options.sort) {
        if (options.direction === 'desc') {
          rql2 = rql.orderBy(r.desc(options.sort));
        } else {
          rql2 = rql.orderBy(options.sort);
        }
      }
      if (!rql2) {
        rql2 = rql;
      }
      return store.utils.Promise.all([

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