Skip to content

blakevanlan/rethinkdb-setup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RethinkDB Setup

Quickly sets up RethinkDB for testing.

Codeship Status for blakevanlan/rethinkdb-setup

Install

npm install rethinkdb-setup

Usage

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) {
   //...   
});

About

Quickly sets up RethinkDB for testing

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •