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

castle-model

v1.0.15

Published

> 封装的Sequelize作为数据库操作底层,对Sequelize的部分操作进行了简化,语法结构类似于ThinkPHP3.2结构。 需要依赖于 castle-config/castle-controller/sequelize,其它依赖请参见相关库的依然范围 # 典型基础用法 ```typescript //获取模型对象 let model = await this.M('Sex'); //启动事务 await this.startTrans(); //添加数据 await model.add({ UI

Downloads

10

Readme

CastleModel数据库操作类

封装的Sequelize作为数据库操作底层,对Sequelize的部分操作进行了简化,语法结构类似于ThinkPHP3.2结构。 需要依赖于 castle-config/castle-controller/sequelize,其它依赖请参见相关库的依然范围

典型基础用法

//获取模型对象
let model = await this.M('Sex');
//启动事务
await this.startTrans();
//添加数据
await model.add({ UID: 6, Sex: 1 });
//批量添加
await model.addAll([
    {
        UID: 6, Sex: 1
    },
    {
        UID: 8, Sex: 1
    },
])
//更新数据
await model.where({ UID: { gt: 7 } }).limit(1).save({ Sex: 100 });
//自增自减处理,UID>7的Sex全部-1,UID+1
await model.where({ UID: { gt: 7 } }).incOrDec({ Sex: -1, UID: 1 })
//当存在DTime时自动做软删除,否则就是硬删除
await model.where({ UID: { gt: 8 } }).del()
//查询单个
await model.where({ UID: { gt: 8 } }).find()
//分页查询多个
await model.where({ UID: { gt: 1 } }).page(1, 10).select()
// 查询并统计
await model.where({ UID: { gt: 1 } }).selectAndCount();
//指定字段查询
await model.fields('UID').find()
//排除字段查询
await model.fields('UID', true).find()
//批量条件更新,仅支持MySQL
await model.caseSave([{ field: { case: 'UID', save: "Sex" }, data: { 1: 2, 5: 10, 7: "`Sex`+5" } }])
//执行自定义SQL查询,通过__DB_PREFIX__注入表前缀
await model.query(`SELECT * FROM __DB_PREFIX__sex`)
//执行自定义SQL,
await model.exec(`UPDATE Sex SET UID=UID+1`, 'UPDATE')
//执行存储过程或函数
await model.exec(`CALL reset();`, 'RAW')
//查询单个字段且只要一个
await model.getFields('Sex');
//查询单个字段且返回数组
await model.getFields('Sex', true);
//支持排序
await model.order('UID DESC').select();
//支持group操作
await model.group(['UID']).fields([[Sequelize.fn('sum', Sequelize.col('UID')), 'UID']]).select()
//支持SUM等统计函数处理
await model.fnField(DbFn.SUM, 'UID', 'UID').group(['Sex']).select();
//支持limit,不适用page方法时
await model.limit(1).select();
//支持直接封装的SUM操作
await model.group(['UID']).sum('UID')
//支持自动检测是否存在,若不存在则自动添加
await model.addIfNotExist({ UID: 10, Sex: 1 })
//也可以自定义存在检测条件
await model.addIfNotExist({ UID: 11, Sex: 1 }, { UID: 11 })
//提交事务,两种方式都行,此处的this指向 BaseController
await this.commit();
await model.commit()
//回滚事务,两种方式都行
await this.rollback();
await model.rollback()
//支持嵌套事务
await this.startTrans();
await this.startTrans();
await this.startTrans();
await this.commit();
await this.commit();
await this.commit();
//当提交次数=开起次数时最后一次提交,之后的commit会报错
await this.commit();
//若中途发生一次rollback调用则会直接抛出错误
await this.rollback()