This commit is contained in:
robin
2022-07-07 22:16:39 +08:00
parent 264ab8d979
commit a9a4bd0981
86 changed files with 1198 additions and 310 deletions
+49 -49
View File
@@ -2,22 +2,22 @@
const Sequelize = require("sequelize");
const xe = require("xe-utils")
module.exports = class Api {
constructor(sequelize,models) {
constructor(sequelize, models) {
this.sequelize = sequelize
this.models = models
this.init()
}
init() {
this.tableName = ""
this.tableWhere = ""
this.tableData = ""
this.tablePage = ""
this.tableLimit = ""
this.tableOrder = ""
this.tableGroup = ""
this.tableAttributes = ""
this.t = ""
this.tableName = null
this.tableWhere = null
this.tableData = null
this.tablePage = null
this.tableLimit = null
this.tableOrder = null
this.tableGroup = null
this.tableAttributes = null
this.t = null
}
/**
@@ -166,7 +166,7 @@ module.exports = class Api {
}
const res = await this.models[this.tableName].findOne(
{
where: this.tableWhere,
where : this.tableWhere,
transaction: this.t
}
)
@@ -184,12 +184,12 @@ module.exports = class Api {
}
const res = await this.models[this.tableName].findAll(
{
where: this.tableWhere,
offset: (this.tablePage && this.tableLimit) ? this.tablePage - 1 * this.tableLimit : null,
limit: this.tableLimit,
order: this.tableOrder || [['updatedAt', 'DESC']], // 时间排序
group: this.tableGroup,
attributes: this.tableAttributes,
where : this.tableWhere,
offset : (this.tablePage && this.tableLimit) ? this.tablePage - 1 * this.tableLimit : null,
limit : this.tableLimit,
order : this.tableOrder || [['updatedAt', 'DESC']], // 时间排序
group : this.tableGroup,
attributes : this.tableAttributes,
transaction: this.t
}
)
@@ -210,8 +210,8 @@ module.exports = class Api {
}
const res = await this.models[this.tableName].findOrCreate(
{
defaults: this.tableData,
where: this.tableWhere,
defaults : this.tableData,
where : this.tableWhere,
transaction: this.t
}
)
@@ -232,12 +232,12 @@ module.exports = class Api {
}
const {count, rows} = await this.models[this.tableName].findAndCountAll(
{
where: this.tableWhere,
offset: (this.tablePage && this.tableLimit) ? this.tablePage - 1 * this.tableLimit : null,
limit: this.tableLimit,
order: this.tableOrder || [['updatedAt', 'DESC']], // 时间排序
group: this.tableGroup,
attributes: this.tableAttributes,
where : this.tableWhere,
offset : (this.tablePage && this.tableLimit) ? this.tablePage - 1 * this.tableLimit : null,
limit : this.tableLimit,
order : this.tableOrder || [['updatedAt', 'DESC']], // 时间排序
group : this.tableGroup,
attributes : this.tableAttributes,
transaction: this.t
}
)
@@ -264,7 +264,7 @@ module.exports = class Api {
let res = await this.models[this.tableName].findOne(
{
where: this.tableWhere,
where : this.tableWhere,
transaction: this.t
}
)
@@ -279,7 +279,7 @@ module.exports = class Api {
await this.models[this.tableName].update(
data,
{
where: this.tableWhere,
where : this.tableWhere,
transaction: this.t
}
)
@@ -296,14 +296,14 @@ module.exports = class Api {
await this.models[this.tableName].decrement(
this.tableData,
{
where: this.tableWhere,
where : this.tableWhere,
transaction: this.t
}
)
res = await this.models[this.tableName].findOne(
{
where: this.tableWhere,
where : this.tableWhere,
transaction: this.t
}
)
@@ -329,7 +329,7 @@ module.exports = class Api {
}
let res = await this.models[this.tableName].findOne(
{
where: this.tableWhere,
where : this.tableWhere,
transaction: this.t
}
)
@@ -344,7 +344,7 @@ module.exports = class Api {
await this.models[this.tableName].update(
data,
{
where: this.tableWhere,
where : this.tableWhere,
transaction: this.t
}
)
@@ -361,14 +361,14 @@ module.exports = class Api {
await this.models[this.tableName].increment(
this.tableData,
{
where: this.tableWhere,
where : this.tableWhere,
transaction: this.t
}
)
res = await this.models[this.tableName].findOne(
{
where: this.tableWhere,
where : this.tableWhere,
transaction: this.t
}
)
@@ -387,10 +387,10 @@ module.exports = class Api {
const res = await this.models[this.tableName].count(
this.tableData,
{
where: this.tableWhere,
order: this.tableOrder || [['updatedAt', 'DESC']], // 时间排序
group: this.tableGroup,
attributes: this.tableAttributes,
where : this.tableWhere,
order : this.tableOrder || [['updatedAt', 'DESC']], // 时间排序
group : this.tableGroup,
attributes : this.tableAttributes,
transaction: this.t
}
)
@@ -408,10 +408,10 @@ module.exports = class Api {
const res = await this.models[this.tableName].sum(
this.tableData,
{
where: this.tableWhere,
order: this.tableOrder || [['updatedAt', 'DESC']], // 时间排序
group: this.tableGroup,
attributes: this.tableAttributes,
where : this.tableWhere,
order : this.tableOrder || [['updatedAt', 'DESC']], // 时间排序
group : this.tableGroup,
attributes : this.tableAttributes,
transaction: this.t
}
)
@@ -429,10 +429,10 @@ module.exports = class Api {
const res = await this.models[this.tableName].max(
this.tableData,
{
where: this.tableWhere,
order: this.tableOrder || [['updatedAt', 'DESC']], // 时间排序
group: this.tableGroup,
attributes: this.tableAttributes,
where : this.tableWhere,
order : this.tableOrder || [['updatedAt', 'DESC']], // 时间排序
group : this.tableGroup,
attributes : this.tableAttributes,
transaction: this.t
}
)
@@ -450,10 +450,10 @@ module.exports = class Api {
const res = await this.models[this.tableName].min(
this.tableData,
{
where: this.tableWhere,
order: this.tableOrder || [['updatedAt', 'DESC']], // 时间排序
group: this.tableGroup,
attributes: this.tableAttributes,
where : this.tableWhere,
order : this.tableOrder || [['updatedAt', 'DESC']], // 时间排序
group : this.tableGroup,
attributes : this.tableAttributes,
transaction: this.t
}
)