コード例 #1
0
ファイル: replace.js プロジェクト: motion/horizon
          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))),
コード例 #2
0
ファイル: aggregation.js プロジェクト: joeybaker/reqlite
 var query = r.db(TEST_DB).table(TEST_TABLE).max(function(doc) {
   return r.branch(
       doc('id').eq(2),
       r.error('bar'),
       doc('id')
   )
 });
コード例 #3
0
 it('forEach - 5', function(done) {
   var query = r.expr([1,r.error('foo'),3,10]).forEach({
     deleted: 0,
     errors: 0,
     inserted: 0,
     replaced: 0,
     skipped: 1,
     unchanged: 1
   });
   compare(query, done);
 });
コード例 #4
0
ファイル: store.js プロジェクト: motion/horizon
                   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),
                                 old_row(hz_v).default(-1).ne(new_row(hz_v))),
                           r.error(writes.invalidated_msg),

                           // Otherwise, we can safely overwrite the row
                           writes.apply_version(new_row, old_row(hz_v).default(-1).add(1))
                         )
                       ), { returnChanges: 'always' }),
コード例 #5
0
ファイル: modifier.js プロジェクト: geek/penseur
    return function (item) {

        const without = [];
        const wrapped = internals.wrap(changes, without, item, []);

        let update = null;
        if (wrapped) {
            if (without.length) {
                update = item.without(without).merge(wrapped);
            }
            else {
                update = item.merge(wrapped);
            }
        }
        else {
            update = item.without(without);
        }

        return RethinkDB.branch(RethinkDB.eq(item, null), RethinkDB.error('No document found'), update);
    };
コード例 #6
0
ファイル: update.js プロジェクト: Alanz2223/horizon
 r.table(table.name).get(row('id')).replace((old) =>
  r.branch(old.ne(null), old.merge(row),
    r.error(r.expr(`The document with id `)
             .add(row('id').toJSON())
             .add(` was missing.`)))));
コード例 #7
0
ファイル: metadata.js プロジェクト: LukeInkster/JSCorpus
 .do((res) =>
   r.branch(res('new_val').eq(null),
            r.error(res('error')),
            res('new_val'))).run(this._conn),
コード例 #8
0
ファイル: term-classes.js プロジェクト: tjmehta/validate-reql
// The exported object here maps from reql term type name (keys in
// protodef.Term.TermType) to an example AST term instance.
//
// This is necessary because the JavaScript rethinkdb driver does not export
// its AST classes, but we need to reconstruct the AST in order to run
// toString() on the query.

var instances = {
  DATUM: r(1),
  MAKE_ARRAY: r([]),
  MAKE_OBJ: r({}),
  VAR: r(function (x) { return x }).args[1],
  JAVASCRIPT: r.js(''),
  UUID: r.uuid(),
  HTTP: r.http(''),
  ERROR: r.error(),
  IMPLICIT_VAR: r.row,
  DB: r.db(''),
  TABLE: r.table(''),
  GET: r({}).get(''),
  GET_ALL: r({}).getAll(''),
  EQ: r.eq(),
  NE: r.ne(),
  LT: r.lt(),
  LE: r.le(),
  GT: r.gt(),
  GE: r.ge(),
  NOT: r.not(),
  ADD: r.add(),
  SUB: r.sub(),
  MUL: r.mul(),
コード例 #9
0
ファイル: reql-queries.js プロジェクト: tjmehta/ast-to-reql
 r.table('marvel').get('IronMan').do(function (ironman) {
   return r.branch(ironman('victories').lt(ironman('battles')),
                   r.error('impossible code path'),
                   ironman)
 }),
コード例 #10
0
ファイル: aggregation.js プロジェクト: joeybaker/reqlite
 ]).group(function(doc) {
   return doc('id').default(r.error('bar'));
 });
コード例 #11
0
 it('default - 5', function(done) {
   var query = r.error('foo').default('bar');
   compare(query, done);
 });
コード例 #12
0
 it('count - 3', function(done) {
   var query = r.error(1);
   compare(query, done);
 });
コード例 #13
0
 it('error - 2', function(done) {
   var query = r.error('foo', 'bar');
   compare(query, done);
 });
コード例 #14
0
 it('error - 1', function(done) {
   var query = r.error('Hello');
   compare(query, done);
 });
コード例 #15
0
 it('branch - 24', function(done) {
   var query = r.branch(true,
   r.error('foo'),
   'bar')
   compare(query, done)
 })