open-renamer/openRenamerBackend/dao/ApplicationRuleDao.ts

64 lines
1.7 KiB
TypeScript
Raw Permalink Normal View History

2021-12-06 23:26:38 +08:00
import ErrorHelper from "../util/ErrorHelper";
2022-11-29 23:02:06 +08:00
import ApplicationRule from "../entity/po/ApplicationRule";
2021-12-06 23:26:38 +08:00
import SqliteHelper from "../util/SqliteHelper";
export default class ApplicationRuleDao {
/**
*
* @param obj
* @returns
*/
static async getAll(): Promise<Array<ApplicationRule>> {
let res = await SqliteHelper.pool.all('select id,createdDate,updatedDate,name,comment,content from application_rule');
return res;
}
2022-11-29 23:02:06 +08:00
/**
* id
* @param id id
* @returns
*/
static async getById(id: number): Promise<ApplicationRule> {
let res = await SqliteHelper.pool.get('select * from application_rule where id=?', id);
return res;
}
2021-12-06 23:26:38 +08:00
/**
*
* @param obj
* @returns
*/
static async addOne(obj: ApplicationRule): Promise<number> {
let res = await SqliteHelper.pool.run('insert into application_rule(createdDate,updatedDate,name,comment,content) values(?,?,?,?,?)'
, obj.createdDate, obj.updatedDate, obj.name, obj.comment, obj.content);
return res.lastID;
}
/**
*
* @param obj
*/
static async updateOne(obj: ApplicationRule): Promise<void> {
let res = await SqliteHelper.pool.run('update application_rule set updatedDate=?,name=?,comment=?,content=? where id=?'
, obj.updatedDate, obj.name, obj.comment, obj.content, obj.id);
if (res.changes == 0) {
throw ErrorHelper.Error404("数据不存在");
}
}
/**
*
* @param id
*/
static async delete(id: number): Promise<void> {
let res = await SqliteHelper.pool.run('delete from application_rule where id=?', id);
if (res.changes == 0) {
throw ErrorHelper.Error404("数据不存在");
}
}
2021-11-22 16:59:38 +08:00
}