A RethinkDB driver plugin to bootstrap all databases, tables and indexes on init.
var r = require(‘rethinkdb-init’)(require(‘rethinkdb’));
r.init({
host: ‘localhost’,
port: 28015,
db: ‘helloDatabase’
}, [{
name: ‘helloTable’,
indexes: [‘superIndex’]
}]
});
rethinkdb-init
orrethinkdb-bootstrap
?- Append to prototype or provide a function?
- Take in a two arguments (a connection and a schema) or one big object?
- What should be the right name for what you’re passing? It’s not really a schema?
- What should the callback/promise return? should it return a connection?
- Should it add the promises to the object? I don’t think so!
- Add seed data variables so that it adds data automatically!
require(‘rethinkdb-init’);
or
require(‘rethinkdb-bootstrap’);
require('rethinkdb-seed');
require('rethinkdb-quickstart');
Provide a function
// #1
var r = require(‘rethinkdb’);
var rInit = require(‘rethinkdb-init’);
or Decorator that returns nothing
// #2
var r = require(‘rethinkdb’);
require(‘rethinkdb-init’)(r);
or Decorator that returns r instance
// #3
var r = require(‘rethinkdb’);
var r = require(‘rethinkdb-init’)(r);
or Decorator that returns r function
// #4
var r = require(‘rethinkdb’);
var rInit = require(‘rethinkdb-init’)(r);
r.init()
Should it take one argument for the connection and another for the schema?
// #1
r.init({
host: ‘localhost’,
port: 28015,
db: ‘sharejs’
}, [{
name: ‘helloDatabase’,
tables: [‘helloTable’]
}]
);
or
// #2
r.init({
conneciton: {
host: ‘localhost’,
port: 28015,
db: ‘sharejs’
},
databases: [{
name: ‘helloDatabase’,
tables: [‘helloTable’]
}]
});
- schema
- blueprint
- seed
What should the init promise return?
// #1
r.init({
host: ‘localhost’,
port: 28015,
db: ‘sharejs’
}, [{
name: ‘helloDatabase’,
tables: [‘helloTable’]
}]
}).then(function (conn) {
// Store it for later
r.conn = conn;
});
// #1
var promise = r.init(config, { });
promise.then(function (conn) {
// Do something
});
or
// #2
r.init(config, { });
// Automatically add promise
r.ready.then(function (conn) {
// Do Something
});