Created
April 20, 2015 20:00
-
-
Save deontologician/a769827f06a593e60064 to your computer and use it in GitHub Desktop.
connection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var r = require('rethinkdb'), | |
connection; | |
r.connect( {host: 'localhost', port: 28015} ) | |
.then(function(conn) { | |
console.log('connected to RethinkDB'); | |
connection = conn; | |
return r.dbList().run(conn); | |
}).then(function(dbs){ | |
console.log('dbs: ' + dbs); | |
if (dbs.indexOf('aqua') == -1) { | |
console.log('about to create db'); | |
return r.dbCreate('aqua').run(connection) | |
.catch(function(err) { | |
console.log('Cannot create database.'); | |
throw err; | |
}).then(function(dbCreationResult) { | |
connection.use('aqua'); | |
return r.tableCreate('products').run(connection); | |
}).catch(function(err) { | |
console.log('Cannot create table <products>.'); | |
throw err; | |
}).then(function(conn) { | |
return r.table('products').insert({product: 'Novac'}).run(connection); | |
}); | |
} | |
}).error(function(err) { | |
console.log('RethinkDB seems unavailable. Aborting.'); | |
throw err; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment