open-renamer/openRenamerBackend/dao/GlobalConfigDao.ts

69 lines
1.7 KiB
TypeScript
Raw Permalink Normal View History

2022-11-29 23:02:06 +08:00
import ErrorHelper from "../util/ErrorHelper";
import SqliteHelper from "../util/SqliteHelper";
import GlobalConfig from "../entity/po/GlobalConfig";
export default class GlobalConfigDao {
/**
*
* @param obj
* @returns
*/
static async addOne(obj: GlobalConfig): Promise<void> {
await SqliteHelper.pool.run('insert into global_config(code,val,description) values(?,?,?)'
, obj.code, obj.val, obj.description);
}
/**
*
* @param code code
* @param val val
*/
static async updateOne(code: string, val: string): Promise<void> {
await SqliteHelper.pool.run('update global_config set val=? where code=?', val, code);
}
/**
*
* @param code
*/
static async deleteByCode(code: string): Promise<void> {
let res = await SqliteHelper.pool.run('delete from global_config where code=?', code);
if (res.changes == 0) {
throw ErrorHelper.Error404("数据不存在");
}
}
/**
*
* @param code
*/
static async getByCode(code: string): Promise<string> {
let res = await SqliteHelper.pool.get('select val from global_config where code=?', code);
return res ? res.val : null;
2022-12-02 11:04:17 +08:00
}
2022-11-29 23:02:06 +08:00
2022-12-02 11:04:17 +08:00
/**
* code
* @param code
*/
static async getByMulCode(codes: Array<string>): Promise<Array<GlobalConfig>> {
if (codes.length == 0) {
return new Array();
}
let codeStr = codes.map(item => `'${item}'`).join(',');
return await SqliteHelper.pool.all(`select * from global_config where code in (${codeStr})`);
}
/**
*
* @param body body
*/
static async insertOrReplace(body: GlobalConfig): Promise<void> {
await SqliteHelper.pool.run(`insert or replace into global_config values (?,?,?)`, body.code, body.val, body.description);
2022-11-29 23:02:06 +08:00
}
}