Home Reference Source Repository

schema-mapper-api

A module to retrieve, modify and save schemas via node or over HTTP.

build status Docs status

Installation

npm install --save schema-mapper-api

Usage

var Api = require('schema-mapper-api');

// Setup connection to the schema-mapper-store
var store = new Api('http://localhost:9000');

// Retrieve a ProjectCollection
store.getProjectCollection()
  .then(function (projectCollection) {
    var project = {
      name: 'demo', // Project name (similar to a database name)
      version: 1, // Project version (versions is where schema-mapper shines)
      schemas: {
        // The keys in this oject are the unique id's for the schema
        '0': {
          name: 'users', // Schema name (similar to a database table)
          primary: '0', // The schema id of the primary key
          columns: {
            // The keys in this object are the unique id's for the columns
            '0': {
              name: 'id', // Column name (similar to database column name)
              type: 'integer' // Column type (see spec which types are supported)
            },
            '1': {
              name: 'email',
              type: 'string'
            }
          }
        }
      }
    };
    projectCollection.putProject('0', project);
    // Save the ProjectCollection
    // the ProjectCollection will be diffed with it's original version, only the changes will be sent to the store (via the Api), returns promise
    return projectCollection.save();
  })
  .then(function () {
    // The changes from the putProject command above are a project.create change and a project.tag change,
    // after these changes have been applied the storage engines are ready to accept data
    var item = {
      id: 1,
      email: '[email protected]'
    };
    return store.putItem(projectId, schemaId, item);
  });

API docs

For more methods on the store, see the docs at Api Docs

For more methods on the project collection, see the docs at ProjectCollection Docs

Licence

MIT