Commit 8d557789 by ning

新增数据库操作

parent 8acad22c
import { Globals } from '../utils/Globals';
import { Logger } from '../utils/Logger';
import BaseTable from './BaseTable';
import { DatabaseImpl } from './DatabaseImpl';
export class SQLiteContext {
static init(context) {
globalThis.sqliteContext = context;
}
/**
* 传入数据库表类,获取对应的表对象,进行相应的增删改查操作
* @param tableClass
*/
static with<T extends BaseTable<any>>(tableClass: { new(dbName, tableName): T }): T {
let dbName = Reflect.getMetadata('Database', tableClass)
if (!dbName) {
throw new Error('table db is empty')
}
Logger.info(this, 'dbName=' + dbName)
let database = Globals.getOrCreate(dbName, () => {
return new DatabaseImpl(dbName);
})
return database.getTable(tableClass)
}
}
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论