Commit cd1ed541 by ning

系统配置数据服务

parent 062e0ebd
...@@ -26,7 +26,7 @@ export default abstract class BaseTable<T> implements ITable { ...@@ -26,7 +26,7 @@ export default abstract class BaseTable<T> implements ITable {
* 初始化数据库 * 初始化数据库
*/ */
private async initDb(): Promise<rdb.RdbStore> { private async initDb(): Promise<rdb.RdbStore> {
Logger.info(this, '初始化数据库,dbName=' + this.dbName + ',tableName=' + this.tableName); Logger.info(this, '初始化数据库,[dbName=' + this.dbName + ',tableName=' + this.tableName + ']');
let db = await rdb.getRdbStore(getContext(this), { let db = await rdb.getRdbStore(getContext(this), {
name: this.dbName, name: this.dbName,
securityLevel: rdb.SecurityLevel.S1 securityLevel: rdb.SecurityLevel.S1
...@@ -57,7 +57,7 @@ export default abstract class BaseTable<T> implements ITable { ...@@ -57,7 +57,7 @@ export default abstract class BaseTable<T> implements ITable {
} }
bindToValuesBucket(bucket: ValuesBucket, item: T) { bindToValuesBucket(bucket: ValuesBucket, item: T) {
Logger.info(this,"表结构数据>>" + JSON.stringify(this.getTableColumns())) Logger.info(this, "表结构数据>>" + JSON.stringify(this.getTableColumns()))
this.getTableColumns().forEach((col) => { this.getTableColumns().forEach((col) => {
bucket[col] = item[col] bucket[col] = item[col]
}) })
......
...@@ -16,7 +16,7 @@ export class DatabaseImpl implements IDatabase { ...@@ -16,7 +16,7 @@ export class DatabaseImpl implements IDatabase {
return Globals.getOrCreate(this.dbName + '_' + tableClass.name, () => { return Globals.getOrCreate(this.dbName + '_' + tableClass.name, () => {
let tableName = Reflect.getMetadata('TableName', tableClass) let tableName = Reflect.getMetadata('TableName', tableClass)
if (!tableName) { if (!tableName) {
throw new Error('table name is empty') throw new Error('[数据库异常]|未设置数据库表名')
} }
return new tableClass(this.dbName, tableName); return new tableClass(this.dbName, tableName);
}); });
......
...@@ -13,7 +13,7 @@ export default interface ITable { ...@@ -13,7 +13,7 @@ export default interface ITable {
getColumnId(): string getColumnId(): string
/** /**
* 获取数据库表 * 获取数据库表
*/ */
getTableColumns(): string[] getTableColumns(): string[]
......
...@@ -10,15 +10,15 @@ export class SQLiteContext { ...@@ -10,15 +10,15 @@ export class SQLiteContext {
/** /**
* 传入数据库表类,获取对应的表对象,进行相应的增删改查操作 * 传入数据库表类,获取对应的表对象,进行相应操作
* @param tableClass * @param tableClass
*/ */
static with<T extends BaseTable<any>>(tableClass: { new(dbName, tableName): T }): T { static with<T extends BaseTable<any>>(tableClass: { new(dbName, tableName): T }): T {
let dbName = Reflect.getMetadata('Database', tableClass) let dbName = Reflect.getMetadata('Database', tableClass)
if (!dbName) { if (!dbName) {
throw new Error('table db is empty') throw new Error('数据库为空')
} }
Logger.info(this, 'dbName=' + dbName) Logger.info(this, '[数据库信息]|[dbName=' + dbName + ']')
let database = Globals.getOrCreate(dbName, () => { let database = Globals.getOrCreate(dbName, () => {
return new DatabaseImpl(dbName); return new DatabaseImpl(dbName);
}) })
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论