介绍
A flexible, lightweight and powerful Object-Relational Mapper for Node.js.
ThinkORM是一个可扩展轻量级的功能丰富的ORM,运行在Node.js环境,已经支持Typescript。
ThinkORM试图用一种抽象的DSL语言,尽量保持各种数据库书写语法一致,用户专注于数据操作逻辑而非具体的数据存储类型,达到快速开发和移植的目的。
特性
- 基于Knex.js实现,支持 Mysql/MariaDB, PostgresSql, SQLite3, Oracle, MSSQL.
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
-
抽象的面向对象式SQL操作语言,保持各种数据库书写语法一致,方便开发和项目迁移
-
支持schema定义数据结构,支持严格的类型检查;支持数据结构迁移到数据库,通过migrate方法调用
-
支持hasone,hasmany,manytomany关联查询
-
支持left,right,inner join查询,支持count,sum,group查询
-
支持连接池配置.支持数据链接检测以及自动重联,数据库服务的宕机修复后无需重启应用
-
支持事务操作,包括同模型、跨模型、并行事务(Mysql/MariaDB, PostgresSql)
-
支持数据自动验证以及自定义规则验证,且规则可扩展
-
支持前置、后置逻辑处理
安装
npm install thinkorm --save
使用
//class User.jsconst BaseModel helper = ; const User = // 构造方法 { // 模型名称,映射实体表 user thismodelName = 'user'; // 数据表字段信息 thisfields = id: type: 'integer' pk: true name: type: 'string' size: 30 index: true defaults: '' ; } //CURDconst userModel = config;// addlet result = await userModel; // deleteresult = await userModel; // updateresult = await userModel; // select result = await userModel; //limit 1result = await userModel; //query name is not null
文档
贡献者
- richenlin
- richerdlee
协议
MIT