1.0.26 • Published 8 years ago
zbmy-orm v1.0.26
中北明夷ORM
安装
npm install zbmy-orm
初始化db,这里区分读写库。
添加oracle支持,配置文件添加dialect = "oracle"
var writeConfig = {
dialect: "oracle",
database: 'dbName',
username: "xxx",
password: "xxx",
option: {
dialect: "oracle"
},
modelPath: path.join(__dirname, 'models') //这里标识model数据模板存储位置,绝对路径。
};
var orm = require('zbmy-orm');
orm.init('mysql','read', writeConfig);//P1为自定义名称,P2为读写类型(read,write,all),P3为数据库参数配置,基本参照sequelize的标准,需要注意modelPath参数;
model定义
"use strict"
var Sequelize = require('sequelize');
module.exports = function(sequelize){
var Company = sequelize.define('company',{
_id: {
type: Sequelize.UUID,
primaryKey: true,
defaultValue: Sequelize.UUIDV1
},
openid: {
type: Sequelize.STRING
}
},{
freezeTableName: true,
timestamps: false,
paranoid: true,
underscored: true
});
return Company;
}
业务逻辑
//findAll方法
orm('gamer').findAll({where:{_id:"xxx"}}, function(err, result){
//err 错误信息
//result 数据信息
});
//事务
orm('gamer').transaction({isolationLevel: "xxxx", deferrable: "xxx", autocommit: false}, function(t){
orm('gamer').findAll({where: {_id: "xxx"}}, {transaction: t}, function(err, result){
if(err){t.rollback();}
t.commit();
});
});
//sql query
orm('gamer').invokeSQL({sql: "xxx", options: {}}, function(err, result){
/*
result = {
data: data,
metadata: metadata
}
*/
});
API 支持
- read方法:
find
findOrCount count
max
min
sum - write方法:
findOrCreate
create
update
destroy increment
decrement
bulkCreate
transaction
invokeSQL - read in write for transaction and sql
w_findAll
w_findOrCount w_count
w_max
w_min
w_sum
1.0.26
8 years ago
1.0.25
8 years ago
1.0.24
9 years ago
1.0.23
9 years ago
1.0.22
9 years ago
1.0.21
9 years ago
1.0.20
9 years ago
1.0.19
9 years ago
1.0.18
9 years ago
1.0.17
9 years ago
1.0.16
9 years ago
1.0.15
9 years ago
1.0.14
9 years ago
1.0.13
9 years ago
1.0.12
9 years ago
1.0.11
9 years ago
1.0.10
9 years ago
1.0.9
9 years ago
1.0.8
9 years ago
1.0.7
10 years ago
1.0.6
10 years ago
1.0.5
10 years ago
1.0.4
10 years ago
1.0.3
10 years ago
1.0.2
10 years ago
1.0.1
10 years ago
1.0.0
10 years ago