Quickly sets up RethinkDB for testing.
npm install rethinkdb-setup
Connect to a RethinkDB and set up tables.
var RethinkdbSetup = require('rethinkdb-setup')
var config = {
connection: {
// Connection config, passed straight to r.connect.
db: "test" // sets the default db
host: "localhost" // sets the host
},
tables: {
// Creates 'table0' with normal primary key.
table0: true,
// Creates 'table1' with normal primary key.
table1: "id",
// Creates 'table2' with 'primaryKey' as the primary key.
table2: "primaryKey",
// Creates 'table3' with 'primaryKey' as the primary key and adds a
// seconardy index on email.
table3: ["primaryKey", "email"],
// Creates 'table4' with normal primary key and adds a geo index to 'location'.
table4: ["id", {name: "location", indexFunction: null, options: {geo: true}}],
// Creates 'table5' with normal primary key and adds an index with an arbitrary
// ReQL expression.
table5: [
"id",
{
name: "fullname",
indexFunction: function(user) {
return r.add(user("last_name"), "_", user("first_name"));
})
}
]
}
};
// NOTE: The rethinkdb module checks the validity of the connection using
// a instanceof meaning that the module can throw an error if two different
// versions are being used with the same connection.
RethinkdbSetup.connectAndSetup(config, function (err, connection) {
//...
});
// If you already have a connnection, just pass it to setup directly.
RethinkdbSetup.setup(connection, config, function (err) {
//...
});
Later on, you can then empty the tables.
RethinkdbSetup.empty(connection, config, function (err) {
//...
});
You can also insert data into tables.
data = {
table0: [{id: '123', foo: 'bar'}, {id: '456', foo: 'apples'}]
};
RethinkdbSetup.load(rethinkdbConnection, data, function (err) {
//...
});