super-orm
基于 Node.js 的 MySQL ORM 模块,支持缓存、多 MySQL 连接,支持 TypeScript
安装
$ npm install super-orm --save
环境要求
- Node.js v6.0 及更高版本 - 运行环境
- MySQL 5.6 及更高版本 - SQL 数据存储
- Redis 2.6 及更高版本 - 缓存存储
使用
'use strict'; const Manager = ; const manager = // Redis 连接,用于缓存 // 参考 https://github.com/luin/ioredis/blob/master/API.md#new_Redis redis: host: '127.0.0.1' port: 6379 db: 0 password: '' // 缓存 key 前缀 prefix: 'TEST:' // 缓存世界,秒 ttl: 60 // MySQL 连接,可指定多个,第一个为 Master,其余为 Slave // 参考 https://www.npmjs.com/package/mysql#connection-options connections: host: '127.0.0.1' port: 3306 user: 'root' password: '' database: 'test' connectionLimit: 10 charset: 'utf8mb4' host: '127.0.0.1' port: 13306 user: 'root' password: '' database: 'test' connectionLimit: 10 charset: 'utf8mb4' ; // 注册 Modelmanager; // 使用 Modelmanager ;// 所有接口同时支持 callback 和 promisemanager; // 使用原始连接执行查询,SELECT 语句会在任意连接执行,其它语句只在 Master 连接执行managerconnection ; // 事务(在 Master 连接执行) { const conn = await managerconnection; // 开始事务 await conn; try await conn; await conn; await conn; // 提交事务 await conn; catch err // 回滚事务 await conn; // 释放连接 await conn;};
API 接口
正在整理中
License
MIT License
Copyright (c) 2016 SuperID | 免费极速身份验证服务
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.