How to use the rethinkdb.connect 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 ktbartholomew / tic-tac-toe / bot / index.js View on Github external
var r = require('rethinkdb');
var WebSocket = require('ws');

var ws = new WebSocket('wss://tictac.io/live/');
var conn = null;

r.connect({host: process.env.DB_HOST, db: 'tictactoe'})
.then(function (connection) {
  conn = connection;
});

var emptyGrid = [[null, null, null],[null, null, null],[null, null, null]];

var currentGame = {
  id: null,
  team: null,
  grid: emptyGrid,
  winner: null,
  frames: []
};

var gridToFrame = function (grid) {
  // convert a 2-dimensional grid array to a 9-character string of only [0-2]
github thejsj / realtime-photo-tutorial / server / db.js View on Github external
'host': 'localhost',
  'port': 28015,
  'db': 'realtime_photo_tutorial'
};

r.connections = [];
r.getNewConnection = function () {
  return r.connect(dbConnection)
    .then(function (conn) {
      conn.use(dbConnection.db);
      r.connections.push(conn);
      return conn;
    });
};

r.connect(dbConnection)
  .then(function (conn) {
    r.conn = conn;
    r.connections.push(conn);
    return r.dbCreate(dbConnection.db).run(r.conn)
      .catch(function () {})
      .then(function () {
        r.conn.use(dbConnection.db);
        // Create Tables
        return r.tableList().run(r.conn)
          .then(function (tableList) {
            return q()
              .then(function() {
                if (tableList.indexOf('images') === -1) {
                  return r.tableCreate('images').run(r.conn);
                }
              });
github hendrikswan / realtime-rethink-lessons / lessons / 10_completed / server / index.js View on Github external
let query = r.row('drawingId').eq(drawingId);

  if (from) {
    query = query.and(r.row('timestamp').ge(new Date(from)))
  }

  return r.table('lines')
  .filter(query)
  .changes({ include_initial: true, include_types: true })
  .run(connection)
  .then((cursor) => {
    cursor.each((err, lineRow) => client.emit(`drawingLine:${drawingId}`, lineRow.new_val));
  });
}

r.connect({
  host: 'localhost',
  port: 28015,
  db: 'awesome_whiteboard'
}).then((connection) => {
  io.on('connection', (client) => {
    client.on('createDrawing', ({ name }) => {
      createDrawing({ connection, name });
    });

    client.on('subscribeToDrawings', () => subscribeToDrawings({
      client,
      connection,
    }));

    client.on('publishLine', (line, callback) => handleLinePublish({
      line,
github incrediblesound / nebulaDB / src / write.js View on Github external
function addIncoming(self, recordId, idToAdd){
  return r.connect(self.connection).then(function(conn){
    return r.table('data')
        .get(recordId)
        .update({ in: r.row('in').setInsert(idToAdd) })
        .run(conn);
  })
}
github davidgljay / nametag / horizon / server / src / reql_connection.js View on Github external
_init_connection () {
    this._retry_timer = null

    return r.connect(this._rdb_options).then((conn) => {
      if (this._interrupted_err) {
        return Promise.reject(this._interrupted_err)
      }
      this._conn = conn
      logger.debug('Connection to RethinkDB established.')
      return new Metadata(this._rdb_options.db,
                          conn,
                          this._clients,
                          this._auto_create_collection,
                          this._auto_create_index).ready()
    }).then((metadata) => {
      logger.info('Connection to RethinkDB ready: ' +
        `${this._rdb_options.user} @ ${this._rdb_options.host}:${this._rdb_options.port}`)

      this._metadata = metadata
      this._reconnect_delay = 0
github pedromsilvapt / unicast / src / Database / Database.ts View on Github external
async online () : Promise {
        try {
            const conn = await r.connect( this.server.config.get( 'database' ) );
    
            await conn.close();

            return true;
        } catch ( error ) {
            return false;
        }
    }
github FlowzPlatform / workflow / JobQue / twitter / function / index.js View on Github external
async function checkConnection(crash, delay) {
  var r = require('rethinkdb')
  r.connect({
    db: cxnOptions.db
  }, function(err, conn) {
    if (err) {
      pino().error('\x1b[31m%s\x1b[0m', '... rethinkdb error')
      setTimeout(function() {
        pino().info('\x1b[33m%s\x1b[0m', '... retrying connection')
        checkConnection(true, delay)
      }, 5000)
    } else {
      if (crash) {
        setTimeout(function() {}, delay)
      }
    }
  })
}
async function processSuccess(job) {
github jolson88 / CoreOS-GettingStarted / EndToEnd / src / hello.js View on Github external
function connect() {
    return r.connect({ host: rethinkServer, port: 28015 });
}
github ktbartholomew / tic-tac-toe / app / lib / storage / bootstrap.js View on Github external
return new Promise(function (resolve, reject) {
      if (Connection) {
        return resolve(Connection);
      }

      return r.connect({
        db: DB_NAME,
        host: process.env.RETHINKDB_HOST || 'ttt_db'
      })
      .then(function (conn) {
        Connection = conn;

        return;
      })
      .then(function () {
        return resolve(Connection);
      });
    });
  }

rethinkdb

This package provides the JavaScript driver library for the RethinkDB database server for use in your node application.

Unknown
Latest version published 5 years ago

Package Health Score

58 / 100
Full package analysis