项目作者: tengla

项目描述 :
Easily load fixtures into rethinkdb.
高级语言: JavaScript
项目地址: git://github.com/tengla/rethinkdb-fixtures.git
创建时间: 2016-01-26T11:24:34Z
项目社区:https://github.com/tengla/rethinkdb-fixtures

开源协议:

下载


rethinkdb-fixtures

Easily load fixtures into Rethinkdb. Useful for testing.

Insert

  1. const options = {
  2. db: 'test',
  3. clear: true // This will make sure tables are cleared before inserting.
  4. };
  5. const rdbFix = require('rethinkdb-fixtures')(options);
  6. const Insert = rdbFix.Insert;
  7. const fixture = {
  8. items: [
  9. {
  10. name: 'Bike'
  11. },
  12. {
  13. name: 'Wrench'
  14. }
  15. ],
  16. people: [
  17. {
  18. name: 'Wild Man Fischer'
  19. },
  20. {
  21. name: 'Charles Ponzi'
  22. }
  23. ]
  24. }
  25. };
  26. Insert(fixture).then( (createdObjects) => {
  27. console.log(createdObjects.items, createdObjects.people);
  28. }, console.error);

Delete

  1. const Delete = rdbFix.Delete;
  2. Delete(['items', 'people']).then( (result) => {
  3. console.log(result); // standard rethinkdb change objects
  4. },console.error);

Closing connection

  1. rdbFix.base.close().then( function () {
  2. console.log(`I've closed the connection`);
  3. });

To test:

make sure you have an instance of rethinkdb running somewhere

  1. npm test

Command line usage

To insert:

  1. export RETHINKDB=test
  2. export FIXTURE=./fixtures.json
  3. node ./bin/insert.js

To delete tables

  1. export RETHINKDB=test
  2. export TABLES='table1,table2,table3'
  3. node ./bin/delete.js