How to use the rethinkdb.branch 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 / store.js View on Github external
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' }),
github davidgljay / nametag / horizon / server / src / endpoint / upsert.js View on Github external
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 update the row and increment the version
github davidgljay / nametag / horizon / server / src / endpoint / store.js View on Github external
.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),
                                 old_row(hz_v).default(-1).ne(new_row(hz_v))),
                           r.error(writes.invalidated_msg),
github rethinkdb / horizon / server / src / endpoint / remove.js View on Github external
r.range(row_data.count()).map((index) =>
                r.branch(res('changes')(index)('old_val').eq(null),
                         res('changes')(index).merge({ old_val: { id: row_data(index)('id') } }),
                         res('changes')(index))).coerceTo('array'),
            })))
github rethinkdb / rethinkdb-example-nodejs / todo-angular-express / app.js View on Github external
r.dbList().contains(config.rethinkdb.db).do(function(containsDb) {
      return r.branch(
        containsDb,
        {created: 0},
        r.dbCreate(config.rethinkdb.db)
      );
    }).run(connection, function(err) {
      callback(err, connection);
github ediket / nothinkdb / src / Table.js View on Github external
async ensureTable(connection) {
    debug(`ensureTable ${connection.db}.${this.tableName}...`);
    await r.branch(
      r.tableList().contains(this.tableName).not(),
      r.tableCreate(this.tableName),
      null
    ).run(connection);
    debug(`[done] ensureTable ${connection.db}.${this.tableName}`);
  }
github rethinkdb / rethinkdb-example-nodejs / todo-angular-express / app.js View on Github external
r.tableList().contains('todos').do(function(containsTable) {
      return r.branch(
        containsTable,
        {created: 0},
        r.tableCreate('todos')
      );
    }).run(connection, function(err) {
      callback(err, connection);
github hyperledger / sawtooth-core / families / track_and_trade / server / db / blocks.js View on Github external
.do(foundBlock => {
        return r.branch(foundBlock, foundBlock, blocks.insert(block))
      })
  })
github outmoded / penseur / lib / criteria.js View on Github external
internals.empty = function (path) {

    const selector = path.reduce((memo, next) => memo(next), exports.row);
    return RethinkDB.branch(
        selector.typeOf().eq('ARRAY'), selector.isEmpty(),
        selector.typeOf().eq('OBJECT'), selector.keys().isEmpty(),
        false);
};
github compose-grandtour / node / example-rethinkdb / server.js View on Github external
.do(exists => {
        return r.branch(
          exists,
          {
            tables_created: 0
          },
          r.db("grand_tour").tableCreate("words", {
            replicas: 3
          })
        );
      })
      .run(connection);

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