0.3.1 • Published 9 years ago

rethinkdb-setup v0.3.1

Weekly downloads
202
License
MIT
Repository
github
Last release
9 years ago

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

9 years ago

0.3.0

9 years ago

0.2.3

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.2.0

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago