Files
buy-lite/server/app/service/db.js
2022-12-30 11:53:48 +08:00

32 lines
744 B
JavaScript

const Service = require("egg").Service
class DbService extends Service {
async addOrUpdate(table, form) {
let result
if (!form.id) {//创建
result = await this.app.mysql.insert(table, form)
} else {//更新
result = await this.app.mysql.update(table, form)
}
return result === 1
}
async delete(table, id) {
await this.app.mysql.delete(table, {id})
}
async detail(table, id) {
return await this.app.mysql.get(table, {id})
}
async list(table, params = {}) {
return await this.app.mysql.select(table, {
where: params,
limit: params?.size || 10, // 返回数据量
offset: Math.max(params?.current - 1, 0), // 数据偏移量
})
}
}
module.exports = DbService