Giter Site home page Giter Site logo

rethinkdb-init's Introduction

RethinkDB Init

A RethinkDB driver plugin to bootstrap all databases, tables and indexes on init.

Often times, application code that uses RethinkDB has a significant portion of code meant for creating the database, tables and indexes (examplehttps://github.com/thejsj/image-pin/blob/master/server/db/index.js). This module is meant so that you can pass an object with the required initial state of your database and get a promise/callback for when all the necesary componentes have been added to the database. This removes a lot of boilerplate code from your application code and makes it easier to understand what is needed in the database to run the application.

Examples

Bootstraping a database with a table and an index

var r = require(‘rethinkdb’);
require(‘rethinkdb-init’)(r);

r.init({
    host: ‘localhost’,
    port: 28015,
    db: ‘helloDatabase’
  }, [{
    name: ‘helloTable’,
    indexes: [‘superIndex’]
  }]
});

Bootstraping a database with 2 tables and 2 indexes on one of the tables

var r = require(‘rethinkdb’);
require(‘rethinkdb-init’)(r);

r.init({
    host: ‘localhost’,
    port: 28015,
    db: ‘helloDatabase’
  },
  [
    {
      name: ‘helloTable’,
      indexes: [‘superIndex’, ‘superDuperIndex’]
    },
    ‘anotherTable’
  ]
});

Bootstraping a database with 4 tables with no indexes

var r = require(‘rethinkdb’);
require(‘rethinkdb-init’)(r);

r.init({
    host: ‘localhost’,
    port: 28015,
    db: ‘helloDatabase’
  },
  [
    ‘hello_table’,
    ‘another_table’,
    ‘yet_another_table’,
    ‘one_last_table’,
  ]
});

Bootstraping a database with 1 tables and 1 geo index

var r = require(‘rethinkdb’);
require(‘rethinkdb-init’)(r);

r.init({
    host: ‘localhost’,
    port: 28015,
    db: ‘helloDatabase’
  },
  [
    {
      name: ‘helloTable’,
      indexes: [{
        name: ‘location’,
        geo: true,
      }]
    },
  ]
});

Bootstraping a database with 1 tables and 1 multi+geo index

var r = require(‘rethinkdb’);
require(‘rethinkdb-init’)(r);

r.init({
    host: ‘localhost’,
    port: 28015,
    db: ‘helloDatabase’
  },
  [
    {
      name: ‘helloTable’,
      indexes: [{
        name: ‘location’,
        geo: true,
        multi: true,
      }]
    },
  ]
});

Bootstraping a database with 1 table and 1 index with an indexFunction

var r = require(‘rethinkdb’);
require(‘rethinkdb-init’)(r);

r.init({
    host: ‘localhost’,
    port: 28015,
    db: ‘helloDatabase’
  },
  [
    {
      name: ‘helloTable’,
      indexes: [{
        name: ‘has_location’,
        indexFunction: function (row) {
          return row.hasFields(‘location’);
        },
      }]
    },
  ]
});

Bootstraping a database with 1 table with a different primaryKey, soft durability, 2 replicas, and 2 shards

var r = require(‘rethinkdb’);
require(‘rethinkdb-init’)(r);

r.init({
    host: ‘localhost’,
    port: 28015,
    db: ‘helloDatabase’
  },
  [
    {
      name: ‘helloTable’,
      primaryKey: ‘location’,
      durability: ‘soft’
      replicas: 2,
      shards: 2
    },
  ]
});

rethinkdb-init's People

Contributors

thejsj avatar

Watchers

Michael Fellinger avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.