Skip to content

clout-js-modules/clout-sequelize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

clout-sequelize

Install

In the directory of your clout-js application, do the following;

  1. Install this package
npm install clout-sequelize
  1. Add this module to package.json
{
    ...
    "modules": ["clout-sequelize"]
    ...
}

Configure

Create a new file sequelize.default.js or sequelize.<YOUR_ENV>.js in /conf directory with the following JavaScript.

module.exports = {
    sequelize: {
        database: '<DATABASE>',
        username: '<USERNAME>',
        password: '<PASSWORD>',
        connection: {
            host : '<HOSTNAME>',
            dialect: 'mysql',
            dialectOptions: {
                multipleStatements: true
            },
            logging: false
        },
        sync: false
    }
};

Usage

Place models within /models in your application directory. A sequalize instance will be available within the clout-js scope. e.g. /models/Cart.js

const clout = require('clout-js');
const { Sequelize, sequelize } = clout;

// Refer to the sequelize documentation
var props = {
    classMethods: {
        // custom hook for adding associations to models
        associate(models) {
            models.Cart.belongsTo(Item, { foreignKey: 'itemId' });
            models.Cart.belongsTo(User, { foreignKey: 'userId' });
        }
    }
};

var Cart = sequelize.define('Cart', {
    quantity: { type: Sequelize.INTEGER, allowNull: false, default: 1 }
}, props);

// Extend static functions
Cart.staticFunction = function () {

}

module.exports = Cart;

About

Clout module to leverage sequelize for models

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published