0.0.6 • Published 7 years ago
sequelize-sql v0.0.6
Sequelize sql commander
The command is extention of Sequelizejs. It allows to call Sequelize functions from a terminal.
v0.0.6 Beta Release
- Install in dependence
npm install --save sequelize-sql or yarn add sequelize-sqlInstall Note
- If you're using
module-aliasor 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',
};Demo - Example
Command default
- Exit: exit
- Config: config - see .sequelizerc config
- Sequelize Function: it's similar you call on modelDocumentation
- Run
node_modules/.bin/sequelize-sql $model- model as root$fn- sequelize.fn$op- sequelize.Op$literal- sequelize.literal$sequelize- sequelize assequelizelib
[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']]
})Resources
License
MIT License