rethinkdb-populate

0.2.0 • Public • Published

RethinkDB Populate

Requires node 7 with --harmony flag

const r = require('rethinkdb')
const populate = require('rethinkdb-populate')
 
async function init() {
 
  const db = await r.connect({port: 28015})
 
  await populate(db, {
    users: {indices: ['email'], data: [
      {id: 'demo', name: 'Example User', email: 'demo@example.org'},
    ]},
    devices: {indices: {
      owners: {multi: true},
    }},
    positions: {indices: {
      location: {geo: true},
      deviceTimestamp: {fields: ['device', 'timestamp']},
    }},
  })
 
  // app.listen or whatever
 
}
 
init().catch(console.error)

API

Following formats are allowed:

populate(db, [ // list of tables to create
  {
    name: 'users',
    indices: ['email'], // list of indices to create
    data: [ // list of initial documents to insert (id required)
      {id: 'demo', name: 'Example User', email: 'demo@example.org'},
    ],
  },
  {
    name: 'devices',
    indices: [
      {name: 'owners', multi: true},
    ],
  },
  {
    name: 'positions',
    indices: [
      {name: 'location', geo: true},
      {name: 'deviceTimestamp', fields: ['device', 'timestamp']
    },
  },
])
populate(db, { // list of tables to create
  users: {
    indices: ['email'], // list of indices to create
    data: [ // list of initial documents to insert
      {id: 'demo', name: 'Example User', email: 'demo@example.org'},
    ],
  },
  devices: {
    indices: {
      owners: {multi: true},
    },
  },
  positions: {
    indices: {
      location: {geo: true},
      deviceTimestamp: {fields: ['device', 'timestamp']},
    },
  },
})

Readme

Keywords

none

Package Sidebar

Install

npm i rethinkdb-populate

Weekly Downloads

0

Version

0.2.0

License

MIT

Last publish

Collaborators

  • phaux