The command is extention of Sequelizejs
. It allows to call Sequelize
functions from a terminal.
- Install in dependence
npm install --save sequelize-sql or yarn add sequelize-sql
- If you're using
module-alias
or custom prototype, you should add a file and put path file to config of.sequelizerc
.
// config content
const path = require('path');
module.exports = {
"test": '...',
"production": '...',
"development": '...',
"extension": 'put it in here',
};
- Exit: exit
- Config: config - see .sequelizerc config
- Sequelize Function: it's similar you call on model
- Run
node_modules/.bin/sequelize-sql
$model
- model as root$fn
- sequelize.fn$op
- sequelize.Op$literal
- sequelize.literal$sequelize
- sequelize assequelize
lib
[Model].[Sequelize Function]
Exmaple:
- Find something
User.findAll({ limit: 10, order: [['createdAt', 'desc']] })
- Create something
Post.create({ title: 'Your title', content: 'Something in this', authorId: 1 })
- Include model
Post.findAll({ include: [{ model: $model.User, as: 'author' }] })
- Counting
Post.findAll({
group: ['authorId'],
attributes: ['authorId', [$literal('COUNT(authorId)'), 'total']]
})
or
Post.findAll({
group: ['authorId'],
attributes: ['authorId', [fn('COUNT', '*'), 'total']]
})
MIT License