0.1.3 • Published 7 years ago

seneca-sequelize v0.1.3

Weekly downloads
1
License
MIT
Repository
-
Last release
7 years ago

seneca-sequelize

This plugin makes a microservice out of your sequelize models. It works wrapping your sequelize instance and exposing your model methods as actions.

Install with npm

npm i --save seneca-sequelize

Define your models

// user.js
export default function(sequelize, types) {
  return sequelize.define('user',
    {
      name: types.STRING,
      age: types.INTEGER
    }
  );
}

Load the plugin

import * as Sequelize from 'sequelize';
import * as Seneca from 'seneca';
import senecaSeq from 'seneca-sequelize';

// Setup your seneca instance
const seneca = Seneca();

// Setup your sequelize instance
const sequelize = new Sequelize('user', 'password', 'database', {
  dialect: 'sqlite'
});

/**
 * Initialize the plugin
 * Options:
 *  - sequelize (required): A sequelize instance.
 *  - modelsPath (required): The path where you have defined your sequelize models.
 *  - hooksPath (optional): The path where you have defined your sequelize hooks.
 *  - roleName (Optional): The role that will be used when you call act on seneca to access the generated services.
 */
seneca.use(senecaSeq, {modelsPath: 'dist/test/models/*', sequelize: sequelize, roleName: 'mymodels'});

// Start your seneca service
seneca.listen();

Example of usage with curl, check out sequelize for more examples of queries

curl http://localhost:10101/act -d '
{
  "role": "mymodels"
  "model": "user",
  "cmd": "findAll"
  "payload": {
    "where": {
      "age": {
        "$gt": 20
      }
    }
  }
}
'
0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago