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 🙏

© 2024 – Pkg Stats / Ryan Hefner

orm-sequelize-utils

v1.0.5

Published

orm sequelize utils

Downloads

3

Readme

orm-sequelize-utils

常用方法封装说明

entity方法说明

根据模型定义结构通过sequelize进行模型创建,使用小驼峰进行模型定义,entity会自动把小驼峰写法在数据库中解析成下划线,然后对操作模型的方法进行了拦截封装,对参数数据进行类型检查和默认值赋值等操作

模型定义结构 字段,表名称小驼峰写法

 {
  name: 'tableName',
  fields: {
    id: { type: Sequelize.BIGINT, allowNull: false, primaryKey: true, defaultFn: 'id' },
    creatorId: { type: Sequelize.BIGINT, allowNull: true, field: 'creator_id', defaultFn: 'userId' },
    creatorName: { type: Sequelize.STRING(64), allowNull: true, field: 'creator_name', defaultFn: 'userName' },
    createdAt: { type: Sequelize.DATE, allowNull: true, field: 'created_at' },
    modifierId: { type: Sequelize.BIGINT, allowNull: true, field: 'modifier_id', defaultEqual: 'creatorId', updateFn: 'userId' },
    modifierName: { type: Sequelize.STRING(64), allowNull: true, field: 'modifier_name', defaultFn: 'userName', updateFn: 'userName' },
    updatedAt: { type: Sequelize.DATE, allowNull: true, field: 'updated_at' },
    isRemoved: { type: Sequelize.BOOLEAN, field: 'is_removed', defaultValue: '0' },
    version: { type: Sequelize.BIGINT, allowNull: true, defaultEqual: 'id', updateFn: 'id' }
  },
  uniques: {
      props: ['name'],
      memo: '属性名称'
    }
}

配置说明:
  字段定义自定义属性说明:
    defaultFn:默认值函数,支持的列类型 id:主键列, now 当前日期, userId: 当前用户主键, userName: 当前用户名称, fullId: 树形表主键链列, fullname: 树形表全称列, level: 树形表层级
    defaultEqual:默认值等值列,一般配置表属性
    updateFn:更新值函数  支持的列类型函数同defaultFn
  uniques:
    props: 参与重复验证的属性字段
    memo: 属性名

sequelize操作模型的主要方法

getCondition 解析通过问号传参的方式传进来的参数,形成options对象
访问路径:/items?limit=20&order=id&attributes=name,shortName&offset=10   
解析结果对象:
{
  limit: 20,
  order
}
postCondition 解析通过post方式传进来的参数,形成options
参数对象:
{
  condtionItems: [ {
    filedName: 'name',
    op: 'eq',
    filedValue: 'lp'
  } ],
  order: [ [ 'id' ] ],
  limit: 100,
  offset: 100,
  attributes: [ 'name', 'shortName' ],
  isNotReturnCount: false // 新修改增加
}
解析对象:
{

}
findOne 通过参数对象查询单条数据
参数对象options:
{
  where: {
    id: ctx.params.id,
    orgId: ctx.params.orgId
  }
}
findAll 通过参数对象查询多条数据
参数对象options:
{
  where: {
    id: ctx.params.id
  },
  limit: 100,
  offset: 100,
  order: [ [ 'id' ] ],
  attributes: ['name','shortName']
}
findAndCountAll 分页查找返回总行数与分页后对象
参数对象options:
{
  where: {
    id: ctx.params.id
  },
  limit: 100,
  offset: 100,
  order: [ [ 'id' ] ],
  attributes: ['name','shortName']
}
create 添加操作
参数对象说明:
  values:要添加的对象
  extras: 上下文信息,里面有租户id,组织id,用户id,扩展添加用户名称
  options: 条件对象,添加一般不使用
    where: 查询数据的条件
    returnData: 默认为false 表示添加成功后返回数据的id,为true,返回新增的完整数据
update 修改操作
参数对象说明:
  values:要添加的对象
  extras: 上下文信息,里面有租户id,组织id,用户id,扩展添加用户名称
  options: 条件对象,一般使用{ where: { id: ctx.params.id } }
  reservedProps:保留字段值,不进行更新的字段列表
destroy 删除操作,默认为更新isRemoved字段值
参数对象说明:
options: 条件对象,一般使用{ where: { id: ctx.params.id } }
extras: 上下文信息,里面有租户id,组织id,用户id,扩展添加用户名称
realDesctroy 删除操作,真正从数据库删除
参数对象说明:
options: 条件对象,一般使用{ where: { id: ctx.params.id } }
bulkCreate 批量添加操作
参数对象说明:
  values:要添加的对象
  extras: 上下文信息,里面有租户id,组织id,用户id,扩展添加用户名称
  options: 条件对象,一般使用{ where: { id: ctx.params.id } }
  reservedProps:保留字段值,不进行更新的字段列表