@onehilltech/dab

3.0.0 • Public • Published

dab

A complex data builder that uses simple definitions

npm version Build Status Dependencies Coverage Status

Features

  • Build data models from data definitions to seed databases
  • Compute data values based on other parts of the data model
  • Supports MongoDB via Mongoose
  • Plays nicely with faker.js

Getting Started

First, define your data model.

// demo.js

const dab = require ('@onehilltech/dab');

var data = {
  users: [
    {first_name: 'John', last_name: 'Doe'},
    {first_name: 'Jane', last_name: 'Doe'}
  ],
  
  family: [
    {user1: dab.ref ('users.0'), user2: dab.ref ('users.1'), relationship: 'spouse'}
  ]
};

Direct Integration

Next, build the data model.

// client.js

const backend = require ('@onehilltech/dab-mongodb');

dab.build (data, { backend }).then (models => {
  // model is the final data model  
});

You must provide a target backend for the build. In the example above, the target backend is MongoDB. The result will be a data model where all objects have an _id property, and all computed values are resolved. The returned model can also seed a MongoDB database. Each collection in the data model will contain instances of Mongoose documents.

// client.js

dab.seed (models, conn, { backend }).then (models => {
  // models will be MongoDB models
});

Command-line Usage

It is possible to generate a dab model from the command-line:

dab build <dabfile>

You can even seed a database from the command-line:

dab seed --connection <CONNECTION> <dabfile>

Next Steps

See our Wiki for more details on using dab.

Need help? Contact us

Package Sidebar

Install

npm i @onehilltech/dab

Weekly Downloads

17

Version

3.0.0

License

Apache-2.0

Unpacked Size

64.7 kB

Total Files

50

Last publish

Collaborators

  • onehilltech