Example #1
0
 .do(function(databaseExists) {
     return rethinkDB.branch(
         databaseExists,
         { dbs_created: 0 },
         rethinkDB.dbCreate('smart_lights')
     );
 }).run(connection, function() {
Example #2
0
  }, function(err, connection) {
    if (err) {
      return callback(err);
    }

    conn = connection;

    r.dbCreate(database).run(conn, function(err) {
      if (err) {
        console.log('Database %s already exists. Continuing.', database);
      } else {
        console.log('Database %s created.', database);
      }

      async.forEach(['users', 'todos'], function(table, callback) {
        r.tableCreate(table, {
          primaryKey: 'id'
        }).run(conn, function(err) {
          if (err) {
            console.log('Table %s already exists. Continuing.', table);
          } else {
            console.log('Table %s created.', table);
          }
          callback();
        });
      }, function(err) {
        callback(err);
      });
    });
  });
Example #3
0
	conn = r.connect({db: 'LoLApiChallenge'}, function(err, conn) {
		r.dbCreate('LoLApiChallenge').run(conn, function(err, conn) { console.log('Created DB')})
		r.db('LoLApiChallenge').tableCreate('URF_match_info').run(conn, function(err, conn) { console.log('Created table')})
		r.table('URF_match_info').indexCreate('id').run(conn, function(err, conn) { console.log('Created id index')})
		r.table('URF_match_info').indexCreate('epoch_time').run(conn, function(err, conn) { console.log('Created epoch_time index')})
		r.table('URF_match_info').indexCreate('content').run(conn, function(err, conn) { console.log('Created content index')})
	})
Example #4
0
co(function* coWrap() {
	const connection = yield r.connect(config.site.db);

	try {
		yield r.dbCreate(config.site.db.db).run(connection);
		console.log(`Database '${config.site.db.db}' created successfully.`);
	} catch (err) {
		console.log(`Warning! ${err}`);
	}

	try {
		yield r.db(config.site.db.db).tableCreate("activity").run(connection);
		console.log("Table 'activity' created successfully.");
		// create the secondary indexes
		yield r.db(config.site.db.db).table("activity").indexCreate("timestamp").run(connection);
		yield r.db(config.site.db.db).table("activity").indexCreate("provider").run(connection);
		console.log("Table 'activity' indexes created successfully.");

	} catch (err) {
		console.log(`Warning! ${err}`);
	}

	yield connection.close();
	console.log("\nYou're all set!");
	console.log(`Open http://${config.site.db.host}:8080/#tables to view the database.`);
	process.exit();
}).catch(errorHandler);
Example #5
0
co(function* coWrap() {
	const connection = yield r.connect(config.site.db);

	try {
		yield r.dbCreate(config.site.db.db).run(connection);
		console.log(`Databse '${config.site.db.db}' created successfully.`);
	} catch (err) {
		console.log(`Warning! ${err.msg}`);
	}

	try {
		yield r.db(config.site.db.db).tableCreate("players").run(connection);
		console.log("Table 'players' created successfully.");
	} catch (err) {
		console.log(`Warning! ${err.msg}`);
	}

	try {
		yield r.db(config.site.db.db).tableCreate("lives").run(connection);
		console.log("Table 'lives' created successfully.");
	} catch (err) {
		console.log(`Warning! ${err.msg}`);
	}

	yield connection.close();
	console.log("\nYou're all set!");
	console.log(`Open http://${config.site.db.host}:8080/#tables to view the database.`);
	process.exit();
}).catch(errorHandler);
Example #6
0
exports.setupDB = function(dbConfig, connection) {
  var blogposts = [
    {
      "title": "Lorem ipsum",
      "text": "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
    },
    {
      "title": "Sed egestas",
      "text": "Sed egestas, ante et vulputate volutpat, eros pede semper est, vitae luctus metus libero eu augue. Morbi purus libero, faucibus adipiscing, commodo quis, gravida id, est. Sed lectus."
    }
  ];

  // Create the DB using [`dbCreate`](http://www.rethinkdb.com/api/#js:manipulating_databases-db_create):
  r.dbCreate(dbConfig.db).run(connection, function(err, result) {
    // Create the table using [`tableCreate`](http://www.rethinkdb.com/api/#js:manipulating_tables-table_create):
    r.db(dbConfig.db).tableCreate('blogposts').run(connection, function(err, result) {
      // We insert the sample data iif the table didn't exist:
      if(result && result.created === 1) {
        r.db(dbConfig.db).table('blogposts').insert(blogposts).run(connection, function(err, result) {
          if(result) {
            debug("Inserted %s sample blog posts into table 'blogposts' in db '%s'", result.inserted, dbConfig['db']);
          }
        });
      }
    });
  });
};
Example #7
0
var createDb = function( connection, dbName, callback ){
  r.dbCreate(dbName).run(connection, function(err, result) {
    if (err) throw err;
    connection.use(dbName);
    Util.executeSafely(callback);
  });
};
Example #8
0
 } ).then( dbs => {
   if( !dbs.includes( config.DB_NAME ) ){
     return r.dbCreate( config.DB_NAME ).run( this.conn );
   } else {
     return Promise.resolve();
   }
 } ).then( () => {
Example #9
0
 init = (conn) => r.dbCreate('nametag').run(conn).catch(err => {
   if (err.msg !== 'Database `nametag` already exists.') {
     console.log('err', err)
   }
   return conn
 })
 .then(() => sessionsDBInit(conn))
Example #10
0
 .then(function (conn) {
   r.conn = conn;
   r.connections.push(conn);
   return r.dbCreate('realtime_photo_sharing').run(r.conn)
     .then(function () {})
     .catch(function () {})
     .then(function () {
       r.conn.use('realtime_photo_sharing');
       // Create Tables
       return r.tableList().run(r.conn)
         .then(function (tableList) {
           return q()
             .then(function() {
               if (tableList.indexOf('photos') === -1) {
                 return r.tableCreate('photos').run(r.conn);
               }
             })
             .then(function () {
               if (tableList.indexOf('users') === -1) {
                 return r.tableCreate('users').run(r.conn);
               }
             })
             .then(function () {
               return r.table('users').indexList().run(r.conn)
                 .then(function (indexList) {
                   if (indexList.indexOf('login') === -1) {
                     return r.table('users').indexCreate('login').run(r.conn);
                   }
                 });
             });
         });
     });
 });
Example #11
0
 var containsOrCreate = function(containsDB) {
   return r.branch(
     containsDB,
     { created: 0 },
     r.dbCreate(config.db)
   );
 };
Example #12
0
		R.dbList().contains(Config.rethink.db).run(connection, function (err, doesExist) {
			
			if (err) {
				callback(err);
			};
		
			if (doesExist) {
	  
				console.log('database already exists:', Config.rethink.db);
				
				connection.use(Config.rethink.db);
				
				callback(null, connection);
			}
			else {
			
			  R.dbCreate(Config.rethink.db).run(connection, function (err, result) {

		      if (err) {
						callback(err);
		      };
					
					console.log('a new database created:', Config.rethink.db);
					
					connection.use(Config.rethink.db);
					
					callback(null, connection);
		    });
			}
		});
Example #13
0
 it('dbCreate - 5', function(done) {
   var query = r.dbCreate('foo_bar');
   compare(query, done, function(doc) {
     delete doc.config_changes[0].new_val.id;
     return doc;
   });
 });
Example #14
0
    let createDb = ( next ) => {
      rdb.dbCreate( DB_NAME ).run( this.conn, ( err, res ) => {
        if( err ){ throw err; }

        next();
      } );
    };
bluebird.coroutine(function*() {
    let conn = yield r.connect(config.database);

    // Create the photos table and indexes if they don't already exists
    try {
        yield r.dbCreate(config.database.db).run(conn);
        yield r.tableCreate('photos').run(conn);
        yield r.table('photos').indexCreate('time').run(conn);
    }
    catch (err) {
        if (err.message.indexOf('already exists') < 0)
            console.log(err.message);
    }

    // Every time there's a change to our photo collection
    //  - emit it with Socket.io
    //  - exclude the binary image data to keep the document size small
    (yield r.table('photos').changes().without('image').run(conn)).each((err, item) => {
        // Photo added
        if (item && item.new_val)
            io.sockets.emit('photo added', item.new_val);
        // Photo removed
        else if (item.new_val == null)
            io.sockets.emit('photo removed', item.old_val);
    });
})();
Example #16
0
 .then((result)=>{
     if(result.indexOf('twabot')<0){
         return r.dbCreate('twabot').run(con);
     }else{
         return Promise.resolve(null);
     }
 })
Example #17
0
}, function (err, conn) {
    console.log(err)
    r.dbCreate('pxscale_data')
        .run(conn, function (err) {
            var redirects, colors, o2o;
            
            console.log(err)
            
            conn.use("pxscale_data");
            
            r.tableCreate("redirects").run(conn, function (err, conn) {
                redirects = true;
                finish(redirects, colors, o2o);              
            });
            
            r.tableCreate("colors").run(conn, function (err, conn) {
                colors = true;
                finish(redirects, colors, o2o);
            });
            
            r.tableCreate("o2o").run(conn, function (err, conn) {
                o2o = true;
                finish(redirects, colors, o2o);
            });
        })
});
Example #18
0
 r.dbList().contains(conf.rethinkdb.db).do(function(containsDb) {
   return r.branch(
     containsDb,
     {created: 0},
     r.dbCreate(conf.rethinkdb.db)
   );
 }).run(connection, function(err) {
Example #19
0
  r.connect({host: dbConfig.host, port: dbConfig.port }, function (err, connection) {
    assert.ok(err === null, err);
    r.dbCreate(dbConfig.db).run(connection, function(err, result) {
      if(err) {
        logdebug("[DEBUG] RethinkDB database '%s' already exists (%s:%s)\n%s", dbConfig.db, err.name, err.msg, err.message);
      }
      else {
        logdebug("[INFO ] RethinkDB database '%s' created", dbConfig.db);
      }

      for(var tbl in dbConfig.tables) {
        (function (tableName) {
          r.db(dbConfig.db).tableCreate(tableName, {primaryKey: dbConfig.tables[tbl]}).run(connection, function(err, result) {
            if(err) {
              logdebug("[DEBUG] RethinkDB table '%s' already exists (%s:%s)\n%s", tableName, err.name, err.msg, err.message);
            }
            else {
              logdebug("[INFO ] RethinkDB table '%s' created", tableName);
            }
          });
        })(tbl);
      }
    });
    callback(connection);
  });
Example #20
0
		.then(function(dbs){
			if(_.indexOf(dbs, config.db.db) !== -1) return;

			// create database
			return r.dbCreate(config.db.db).run(conn)

			// create schema and fixture
			.then(function(){

				function requireJSON(f){
					return JSON.parse(fs.readFileSync(f, 'utf8'));
				}

				return Q.all([
					{info: requireJSON(__dirname + '/../test/fixtures/db/cycles.info'), data: require('../test/fixtures/db/cycles.json')},
					{info: requireJSON(__dirname + '/../test/fixtures/db/projects.info'), data: require('../test/fixtures/db/projects.json')},
					{info: requireJSON(__dirname + '/../test/fixtures/db/users.info'), data: require('../test/fixtures/db/users.json')},
					{info: requireJSON(__dirname + '/../test/fixtures/db/notifications.info'), data: require('../test/fixtures/db/notifications.json')},
					{info: requireJSON(__dirname + '/../test/fixtures/db/files.info'), data: require('../test/fixtures/db/files.json')}
				].map(function(fixture) {
					return r.db(config.db.db).tableCreate(fixture.info.name, {primaryKey: fixture.info.primary_key}).run(conn)
					.then(function(){ return r.db(config.db.db).table(fixture.info.name).insert(fixture.data).run(conn); });
				}));
			})
		})
Example #21
0
 init = (conn) => r.dbCreate('demo').run(conn).catch(err => {
   if (err.msg !== 'Database `demo` already exists.') {
     console.log('err', err)
   }
   return null
 })
 .then(() => sessionsDBInit(conn))
Example #22
0
 r.connect({host: dbConfig.host, port: dbConfig.port }, function (err, connection) {
     assert.ok(err === null, err);
     r.dbCreate(dbConfig.db).run(connection, function(err, result) {
         if(err) {
             logdebug("[DEBUG] RethinkDB database '%s' already exists (%s:%s)\n%s", dbConfig.db, err.name, err.msg, err.message);
         }
         else {
             logdebug("[INFO ] RethinkDB database '%s' created", dbConfig.db);
         }
         async.each(dbConfig.tables, function(tbl, cb) {
             ((tableName)=>{
                 r.db(dbConfig.db).tableCreate(tableName).run(connection, function(err, result) {
                     if (err) {
                         logdebug("[DEBUG] RethinkDB table '%s' already exists (%s:%s)\n%s", tableName, err.name, err.msg, err.message);
                     }
                     else {
                         logdebug("[INFO ] RethinkDB table '%s' created", tableName);
                     }
                     cb();
                 });
             })(tbl);
         },(err)=>{
             callback(err);
         });
     });
 });
Example #23
0
            function(err, dblist) {
                if (err) throw err;

                var dbExists = dblist.indexOf('audit') != -1;

                if (dbExists && force) {
                    r.dbDrop('audit').run(connection, function() {});
                }

                if (!dbExists || force) {
                    r.dbCreate('audit').run(connection, function() {});;
                    connection.use('audit');

                    ['courses', 'students', 'requirements', 'degrees'].forEach(function(tableName) {
                        r.db('audit').tableCreate(tableName).run(connection, function (err, result) {
                            if (err) throw err;
                            console.log("create table ", tableName ,": ", JSON.stringify(result, null, 2));
                        })

                        r.table(tableName).insert(model[tableName]).run(connection, function (err, result) {
                            if (err) throw err;
                            console.log("insert bootstrap data into ", tableName, ": ", JSON.stringify(result, null, 2));
                        })
                    })

                }
            }
Example #24
0
 .do(function(databaseExists) {
   return r.branch(
     databaseExists,
     { dbs_created: 0 },
     r.dbCreate(db)
   );
 }).run(conn, function (err, res) {
Example #25
0
 function createDatabase(callback) {
   
 r.dbCreate(config.rethinkdb_name)
         .run(connection, function (err) {
         rdb = r.db(config.rethinkdb_name);
         callback();
     });
 },
Example #26
0
 r.connect({host : config.host, port : config.port},function(err,conn){
   assert.ok(err === null,err);
   r.dbCreate(dbName).run(conn,function(err,result){
     //assert.ok(err === null,err);
     conn.close();
     next(err,result);
   });
 });
Example #27
0
 r.dbList().run(connection, function (listError, databases) {
     if (listError) {
         return callback(listError);
     }
     if (databases.indexOf(db) > -1) {
         return callback();
     }
     r.dbCreate(db).run(connection, callback);
 });
async function syncDB() {
  const connection = await getConnection({ db: null });
  r.branch(
    r.dbList().contains(RETHINKDB.DB).not(),
    r.dbCreate(RETHINKDB.DB),
    null
  ).run(connection);
  await connection.close();
}
Example #29
0
.then(function(dbs){
    if(dbs.indexOf(config.rethinkdb.db) == -1){
        console.log("creating db")
        return q.nsend(r.dbCreate(config.rethinkdb.db), "run", connection)
                .then(function(){console.log("db created")})
    }else{
        console.log("db exists");
    }
})
Example #30
0
 it('Create a database', function(done) {
     r.dbCreate("reqlite").run(connection).then(function(result) {
         assert.deepEqual(result, {created: 1})
         return r.dbList().run(connection);
     }).then(function(result) {
         assert.notEqual(result.indexOf("reqlite"), -1)
         done();
     }).error(done);
 });