Commit 3995052f by 毛勇泽

Merge remote-tracking branch 'origin/master'

parents 78aa52b4 c1174f1a
...@@ -57,12 +57,19 @@ export default abstract class BaseTable<T> implements ITable { ...@@ -57,12 +57,19 @@ 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()))
this.getTableColumns().forEach((col) => { this.getTableColumns().forEach((col) => {
bucket[col] = item[col] bucket[col] = item[col]
}) })
} }
toBucket(bucket: ValuesBucket, item: T): ValuesBucket {
this.getTableColumns().forEach((col) => {
bucket[col] = item[col]
})
return bucket;
}
/** /**
* 清空表 * 清空表
*/ */
...@@ -92,6 +99,27 @@ export default abstract class BaseTable<T> implements ITable { ...@@ -92,6 +99,27 @@ export default abstract class BaseTable<T> implements ITable {
} }
/** /**
* 插入数据
* @param item 插入对象
*/
async batchInsert(item: T[]): Promise<number> {
Logger.info(this, '批量插入数据>>' + JSON.stringify(item))
let bucket = [];
if (item) {
item.forEach(it => {
let tmp = {};
bucket.push(this.toBucket(tmp, it));
})
Logger.info(this, '绑定到Bucket数据>>' + JSON.stringify(bucket))
let db = await this.futureDb;
return db.batchInsert(this.tableName, bucket);
} else {
throw new Error('插入数据为空');
}
}
/**
* 删除数据 * 删除数据
*/ */
async delete(item: T): Promise<number> { async delete(item: T): Promise<number> {
......
import relationalStore from '@ohos.data.relationalStore'; import relationalStore from '@ohos.data.relationalStore';
import { DwInfo } from '../../entity/DwInfo'; import { DwInfo } from '../../entity/DwInfo';
import { Logger } from '../../utils/Logger';
import BaseTable, { ValueType } from '../BaseTable'; import BaseTable, { ValueType } from '../BaseTable';
import { Table } from '../decorator/Decorators'; import { Table } from '../decorator/Decorators';
import { BaseSql } from '../sql/BaseSql';
/** /**
* 单位的数据层 * 单位的数据层
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论