0.0.6 • Published 5 years ago

sequelize-sql v0.0.6

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

Sequelize sql commander

The command is extention of Sequelizejs. It allows to call Sequelize functions from a terminal.

npm version npm downloads node License

v0.0.6 Beta Release

  • Install in dependence
npm install --save sequelize-sql or yarn add sequelize-sql

Install Note

  • 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',
};

Demo - Example

Blog example

Command default

-   Exit: exit
-   Config: config - see .sequelizerc config
-   Sequelize Function: it's similar you call on model

Documentation

  • Run node_modules/.bin/sequelize-sql
  • $model - model as root
  • $fn - sequelize.fn
  • $op - sequelize.Op
  • $literal - sequelize.literal
  • $sequelize - sequelize as sequelize 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']]
    })

Resources

License

MIT License

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago

1.0.0

5 years ago