npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

egg-sequelize-wrapper

v0.0.8

Published

封装了sequelize的增删改方法,where条件书写更加流畅,并可以选择对查询后结果进行预处理

Downloads

42

Readme

egg-sequelize-wrapper

Install

$ npm i egg-sequelize-wrapper --save

Usage

// {app_root}/config/plugin.js
exports.sequelizeWrapper = {
  enable: true,
  package: 'egg-sequelize-wrapper',
};

Example

  • find
// {app_root}/app/service/account.js

const accouts = await this.app.model.Account.$findAndCount({
  where: {
    username_like: 'dev',
    'role.description_or_like': '超级',
    'role.description_or_ne': '2018',
    'role.description_or_and_eq': '上班'
  },
  attributes: [ 'id', 'username', 'password', 'createdAt', 'updatedAt' ],
  order: [[ 'createdAt', 'DESC' ]],
  limit: 10,
  offset: 0,
  include: [
    {
      model: model.Role,
      attributes: [ 'id', 'description' ],
      where: {
        status_in: '1,0',
        createdAt_gte: '2018-01-01',
      },
      required: false,
      through: {
        attributes: [],
        where: { status: 1 },
      },
    },
  ],
}, {
  json: true,
  fields: [
    { origin: 'createdAt', type: 'date' },
    { origin: 'password', type: 'empty' },
    {
      origin: 'roles.id',
      field: 'roles',
    },
  ],
  fat: true,
});

it separate the opts into query options and return options the most import change of query options is where, u can use _(between|like|ne...) / _or_(like|ne..) / _or_and_(like) to simplify the query conditions other attributes which set in sequelize.model.find can also be used in query opts, the detail info u can check lib/components/where.js

in the return options, there are three parameters: json | fields | fat json = true means the returns had been processed by JSON.stringify if json = true, then u can specify every props of the instance, set the rule and return the handled prop, origin is necessary, e.x: companies.staffs.name field is the name of the handled prop, it also support nest set. the detail info u can check lib/components/transform.js

// qeury result
{
    name: 'company name',
    staffs: [
        {
            name: '小a',
            age: 22,
        },
        {
            name: '小b',
            age: 33,
        }
    ],
    header: {
        name: '小c',
        age: '1966-10-10 00:00:00+8:00',
        role: {
            title: 'CEO'
        }
    }
}

const fields = [
    { origin: 'staffs.name', field: 'staffNames' },
    { origin: 'staffs.age', field: 'doubleStaffName', filter: x => x > 30, translate: x => x * 2},
    { origin: 'header.role.title', field: 'headerTitle'},
    { origin: 'header.age', type: 'date' }
]

// if fat = false

return = { 
   staffNames: [ '小a', '小b' ],
   doubleStaffName: [ 66 ],
   headerTitle: 'CEO',
   header: { age: '1966-10-10' } 
}

// else

return = 
{ name: 'company name',
  staffs: [ { name: '小a', age: 22 }, { name: '小b', age: 33 } ],
  header: { name: '小c', age: '1966-10-10', role: { title: 'CEO' } },
  staffNames: [ '小a', '小b' ],
  doubleStaffName: [ 66 ],
  headerTitle: 'CEO' }
  • create

it also separate args and return options the args is same like sequelize.model.create, but if the args is array, the function automatically call bulkCreate the return options support relative create


await models.account.$create(
    [
        {
            name: 'a',
            age: 22,
            role: {
                name: 'student'
            }
        }
    ],
    {
        include: [
            {
                model: models.role
            }
        ]
    }
)
  • update

it receive updateOpts and queryOpts, updateOpts can be object or array, queryOpts support include update be careful, include need precondition: id & transaction

await models.account.$update(
    {
        name: 'update a',
        role: {
            name: 'senior student'
        }
    },
    {
        where: {name: 'a'},
        include: [{model: models.role}],
        transaction: t
    }
)

Questions & Suggestions

Please open an issue here.

License

MIT