mm-db-schema

1.1.1 • Public • Published

Matter In Motion. Database schema extension

NPM Version NPM Downloads

Database schema defenition extension for matter in motion framework

Usage

Extensions installation instructions

  1. Add this extension
  2. Add schema extension for your database

Define a schema in your resource controller with options:

  • db — database name. If you use mm-db extension you can omit this. Default database will be used.
  • table — table name or an object with table name and table creation options.
  • indexes — array of index names or an object with index names and index creation options.
  • apply — function. If you define apply function it will be called. table and indexes options will be ignored. However, you still should still define them to use in your code.

You can define as many tables as you want.

Simple example

Controller.prototype.schema = {
  name: {
    table: 'table_name',
    indexes: ['index_name1', 'index_name2']
  }
}

Full example

Controller.prototype.schema = {
  name: {
    db: 'database driver name',
    table: {
      'table_name': tableOptions
    },
    indexes: {
      'index_name1': indexOptions1,
      'index_name2': indexOptions2,
    }
  }
}

Complicated scenarios

Controller.prototype.schema = {
  name: {
    db: 'database driver name',
    //this will be used as description only
    table: 'table_name',
    indexes: ['index_name1', 'index_name2'],
    //here is actual schema
    apply: function(dbDriver, schema) {
      //do any stuff nessesary and return a promise
    }
  }
}

License: MIT.

Package Sidebar

Install

npm i mm-db-schema

Weekly Downloads

0

Version

1.1.1

License

MIT

Unpacked Size

8.79 kB

Total Files

6

Last publish

Collaborators

  • velocityzen