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