Installations
npm install castle-model
Developer Guide
Typescript
Yes
Module System
CommonJS
Score
58.1
Supply Chain
88.2
Quality
73.7
Maintenance
25
Vulnerability
99.6
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (100%)
Developer
YanCastle
Download Statistics
Total Downloads
4,054
Last Day
1
Last Week
7
Last Month
29
Last Year
313
GitHub Statistics
160 Commits
1 Watching
4 Branches
1 Contributors
Bundle Size
1.63 MB
Minified
294.55 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.0.15
Package Id
castle-model@1.0.15
Unpacked Size
32.51 kB
Size
9.86 kB
File Count
7
Total Downloads
Cumulative downloads
Total Downloads
4,054
Last day
0%
1
Compared to previous day
Last week
-61.1%
7
Compared to previous week
Last month
20.8%
29
Compared to previous month
Last year
-43.5%
313
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
3
CastleModel数据库操作类
封装的Sequelize作为数据库操作底层,对Sequelize的部分操作进行了简化,语法结构类似于ThinkPHP3.2结构。 需要依赖于 castle-config/castle-controller/sequelize,其它依赖请参见相关库的依然范围
典型基础用法
1//获取模型对象 2let model = await this.M('Sex'); 3//启动事务 4await this.startTrans(); 5//添加数据 6await model.add({ UID: 6, Sex: 1 }); 7//批量添加 8await model.addAll([ 9 { 10 UID: 6, Sex: 1 11 }, 12 { 13 UID: 8, Sex: 1 14 }, 15]) 16//更新数据 17await model.where({ UID: { gt: 7 } }).limit(1).save({ Sex: 100 }); 18//自增自减处理,UID>7的Sex全部-1,UID+1 19await model.where({ UID: { gt: 7 } }).incOrDec({ Sex: -1, UID: 1 }) 20//当存在DTime时自动做软删除,否则就是硬删除 21await model.where({ UID: { gt: 8 } }).del() 22//查询单个 23await model.where({ UID: { gt: 8 } }).find() 24//分页查询多个 25await model.where({ UID: { gt: 1 } }).page(1, 10).select() 26// 查询并统计 27await model.where({ UID: { gt: 1 } }).selectAndCount(); 28//指定字段查询 29await model.fields('UID').find() 30//排除字段查询 31await model.fields('UID', true).find() 32//批量条件更新,仅支持MySQL 33await model.caseSave([{ field: { case: 'UID', save: "Sex" }, data: { 1: 2, 5: 10, 7: "`Sex`+5" } }]) 34//执行自定义SQL查询,通过__DB_PREFIX__注入表前缀 35await model.query(`SELECT * FROM __DB_PREFIX__sex`) 36//执行自定义SQL, 37await model.exec(`UPDATE Sex SET UID=UID+1`, 'UPDATE') 38//执行存储过程或函数 39await model.exec(`CALL reset();`, 'RAW') 40//查询单个字段且只要一个 41await model.getFields('Sex'); 42//查询单个字段且返回数组 43await model.getFields('Sex', true); 44//支持排序 45await model.order('UID DESC').select(); 46//支持group操作 47await model.group(['UID']).fields([[Sequelize.fn('sum', Sequelize.col('UID')), 'UID']]).select() 48//支持SUM等统计函数处理 49await model.fnField(DbFn.SUM, 'UID', 'UID').group(['Sex']).select(); 50//支持limit,不适用page方法时 51await model.limit(1).select(); 52//支持直接封装的SUM操作 53await model.group(['UID']).sum('UID') 54//支持自动检测是否存在,若不存在则自动添加 55await model.addIfNotExist({ UID: 10, Sex: 1 }) 56//也可以自定义存在检测条件 57await model.addIfNotExist({ UID: 11, Sex: 1 }, { UID: 11 }) 58//提交事务,两种方式都行,此处的this指向 BaseController 59await this.commit(); 60await model.commit() 61//回滚事务,两种方式都行 62await this.rollback(); 63await model.rollback() 64//支持嵌套事务 65await this.startTrans(); 66await this.startTrans(); 67await this.startTrans(); 68await this.commit(); 69await this.commit(); 70await this.commit(); 71//当提交次数=开起次数时最后一次提交,之后的commit会报错 72await this.commit(); 73//若中途发生一次rollback调用则会直接抛出错误 74await this.rollback()
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
19 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-4gxf-g5gf-22h4
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-8hfj-j24r-96c4
- Warn: Project is vulnerable to: GHSA-wc69-rhjr-hc9g
- Warn: Project is vulnerable to: GHSA-56x4-j7p9-fcf9
- Warn: Project is vulnerable to: GHSA-v78c-4p63-2j6c
- Warn: Project is vulnerable to: GHSA-mqr2-w7wj-jjgr
- Warn: Project is vulnerable to: GHSA-49j4-86m8-q2jw
- Warn: Project is vulnerable to: GHSA-fpw7-j2hg-69v5
- Warn: Project is vulnerable to: GHSA-4rch-2fh8-94vw
- Warn: Project is vulnerable to: GHSA-pmh2-wpjm-fj45
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-wrh9-cjv3-2hpw
- Warn: Project is vulnerable to: GHSA-8c25-f3mj-v6h8
- Warn: Project is vulnerable to: GHSA-vqfx-gj96-3w95
- Warn: Project is vulnerable to: GHSA-f598-mfpv-gmfx
- Warn: Project is vulnerable to: GHSA-qgmg-gppg-76g5
Score
1.3
/10
Last Scanned on 2025-02-03
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to castle-model
@ctsy/model
> 封装的Sequelize作为数据库操作底层,对Sequelize的部分操作进行了简化,语法结构类似于ThinkPHP3.2结构。 需要依赖于 castle-config/castle-controller/sequelize,其它依赖请参见相关库的依然范围 # 典型基础用法 ```typescript //获取模型对象 let model = await this.M('Sex'); //启动事务 =1 await this.startTrans(); //添加数据 // INSERT INTO se
author-joined-fierce-lungs
author-joined-fierce-lungs