How to use the rethinkdb.error 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 rethinkdb / horizon / server / src / endpoint / replace.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 replace the row
                       writes.apply_version(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 davidgljay / nametag / horizon / server / src / endpoint / replace.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 replace the row
                       writes.apply_version(new_row, old_row(hz_v).default(-1).add(1))),
              { returnChanges: 'always' }))
github rethinkdb / horizon / server / src / auth.js View on Github external
return Promise.resolve().then(() => {
      const key = this.auth_key(provider, info);
      const db = r.db(this._parent._name);

      const insert = (table, row) =>
        db.table(table)
          .insert(row, { conflict: 'error', returnChanges: 'always' })
          .bracket('changes')(0)('new_val');

      let query = db.table('users')
                    .get(db.table('hz_users_auth').get(key)('user_id'))
                    .default(r.error('User not found and new user creation is disabled.'));

      if (this._create_new_users) {
        query = insert('hz_users_auth', { id: key, user_id: r.uuid() })
          .do((auth_user) => insert('users', this.new_user_row(auth_user('user_id'))));
      }

      return query.run(this._parent._reql_conn.connection()).catch((err) => {
        // TODO: if we got a `Duplicate primary key` error, it was likely a race condition
        // and we should succeed if we try again.
        logger.debug(`Failed user lookup or creation: ${err}`);
        throw new Error('User lookup or creation in database failed.');
      });
    }).then((user) =>
      this._jwt.sign({ id: user.id, provider })
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 davidgljay / nametag / horizon / server / src / endpoint / replace.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 replace the row
                       writes.apply_version(new_row, old_row(hz_v).default(-1).add(1))),
              { returnChanges: 'always' }))
github rethinkdb / horizon / server / src / write.js View on Github external
reql.get(row('id')).replace((old) =>
           r.branch(old.ne(null), old.merge(row),
             r.error(r.expr("The document with id '")
                      .add(row('id').coerceTo('string'))
                      .add("' was missing.")))));
      } else if (conflict === 'replace') {
github davidgljay / nametag / horizon / server / src / metadata / metadata.js View on Github external
r.db(db).table('hz_collections').get(name).replace({ id: name }).do((res) =>
    r.branch(
      res('errors').ne(0),
      r.error(res('first_error')),
      res('inserted').eq(1),
      r.db(db).tableCreate(name),
      res
    )
  ).run(conn)
github rethinkdb / horizon / server / src / metadata / metadata.js View on Github external
.do((res) =>
            r.branch(res('new_val').eq(null),
                     r.error(res('error')),
                     res('new_val'))).run(this._conn),
        r.db(this._db).table('hz_groups').get('admin')

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