1 Star 0 Fork 0

ooooooyun / baas

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
model.js 4.26 KB
一键复制 编辑 原始数据 按行查看 历史
ooooooyun 提交于 2023-10-23 09:54 . 1
const { mysql } = require("./config");
const _knex = require("knex");
const _bookshelf = require("bookshelf");
const uuid = require("bookshelf-uuid");
const paranoia = require("bookshelf-paranoia");
const cache = require("./lib/bookshelf/cache");
const pagination = require("./lib/bookshelf/pagination");
const visibility = require("./lib/bookshelf/visibility");
const getBookshelf = connection => {
const knex = _knex(connection);
const bookshelf = _bookshelf(knex);
bookshelf.plugin(visibility);
bookshelf.plugin(pagination);
bookshelf.plugin(paranoia);
bookshelf.plugin(uuid);
bookshelf.plugin(cache);
return bookshelf;
};
const getModels = connection => {
const bookshelf = getBookshelf({
client: "mysql",
connection: connection
});
const Models = {
baas: bookshelf.Model.extend({
tableName: `${mysql.database}.baas`,
hasTimestamps: true,
softDelete: true
}),
auth: bookshelf.Model.extend({
tableName: `${mysql.database}.auth`,
hasTimestamps: true,
softDelete: true
}),
file: bookshelf.Model.extend({
tableName: `${mysql.database}.file`,
hasTimestamps: true,
softDelete: true
}),
global: bookshelf.Model.extend({
tableName: `${mysql.database}.global`,
hasTimestamps: true,
softDelete: true
}),
class: bookshelf.Model.extend({
tableName: `${mysql.database}.class`,
hasTimestamps: true,
softDelete: true,
// 解密数据
auth: function () {
return this.belongsToMany(Models.auth, "auth_id").through(Models.classAuth, "class_id", "auth_id");
}
}),
classAuth: bookshelf.Model.extend({
tableName: `${mysql.database}.class_auth`,
hasTimestamps: true,
softDelete: true
}),
classTable: bookshelf.Model.extend({
tableName: `${mysql.database}.class_table`,
hasTimestamps: true,
softDelete: true,
// 加密数据
secret: function () {
return this.belongsTo(Models.auth, "auth_id");
}
}),
classField: bookshelf.Model.extend({
tableName: `${mysql.database}.class_field`,
hasTimestamps: true,
softDelete: true
}),
classFunction: bookshelf.Model.extend({
tableName: `${mysql.database}.class_function`,
hasTimestamps: true,
softDelete: true
}),
classHook: bookshelf.Model.extend({
tableName: `${mysql.database}.class_hook`,
hasTimestamps: true,
softDelete: true
}),
classSchedule: bookshelf.Model.extend({
tableName: `${mysql.database}.class_schedule`,
hasTimestamps: true,
softDelete: true
}),
table: bookshelf.Model.extend({
tableName: `${mysql.database}.table`,
hasTimestamps: true,
softDelete: true
}),
relation: bookshelf.Model.extend({
tableName: `${mysql.database}.relation`,
hasTimestamps: true,
softDelete: true
}),
log: {
debug: bookshelf.Model.extend({
tableName: `${mysql.database}_log.debug`,
hasTimestamps: true,
softDelete: true
}),
request: bookshelf.Model.extend({
tableName: `${mysql.database}_log.request`,
hasTimestamps: true,
softDelete: true
}),
sms: bookshelf.Model.extend({
tableName: `${mysql.database}_log.sms`,
hasTimestamps: true,
softDelete: true
})
},
plugin: {
sms: bookshelf.Model.extend({
tableName: `${mysql.database}_plugin.sms`,
hasTimestamps: true,
softDelete: true
}),
captchaImg: bookshelf.Model.extend({
tableName: `${mysql.database}_plugin.captcha_img`,
hasTimestamps: true,
softDelete: true
}),
wehcat: bookshelf.Model.extend({
tableName: `${mysql.database}_plugin.wehcat`,
hasTimestamps: true,
softDelete: true
}),
payWexin: bookshelf.Model.extend({
tableName: `${mysql.database}_plugin.pay_weixin`,
hasTimestamps: true,
softDelete: true
}),
payWxa: bookshelf.Model.extend({
tableName: `${mysql.database}_plugin.pay_wxa`,
hasTimestamps: true,
softDelete: true
}),
payAlipay: bookshelf.Model.extend({
tableName: `${mysql.database}_plugin.pay_alipay`,
hasTimestamps: true,
softDelete: true
}),
mail: bookshelf.Model.extend({
tableName: `${mysql.database}_plugin.mail`,
hasTimestamps: true,
softDelete: true
}),
dms: bookshelf.Model.extend({
tableName: `${mysql.database}_plugin.dms`,
hasTimestamps: true,
softDelete: true
}),
}
};
return {
Models,
bookshelf
};
};
module.exports = {
getBookshelf,
getModels
};
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/xianwenhao/baas.git
git@gitee.com:xianwenhao/baas.git
xianwenhao
baas
baas
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891