提交 d150c48f 编写于 作者: B Benjamin Pasero

storage - use all() over each()

上级 35a3be5b
......@@ -254,9 +254,9 @@ export class SQLiteStorageImpl {
return this.db.then(db => {
const items = new Map<string, string>();
return this.each(db, 'SELECT * FROM ItemTable', row => {
items.set(row.key, row.value);
}).then(() => {
return this.all(db, 'SELECT * FROM ItemTable').then(rows => {
rows.forEach(row => items.set(row.key, row.value));
if (this.logger.verbose) {
this.logger.info(`[storage ${this.name}] getItems(): ${mapToString(items)}`);
}
......@@ -460,29 +460,16 @@ export class SQLiteStorageImpl {
});
}
private each(db: Database, sql: string, callback: (row: any) => void): Promise<void> {
private all(db: Database, sql: string): Promise<{ key: string, value: string }[]> {
return new Promise((resolve, reject) => {
let hadError = false;
db.each(sql, (error, row) => {
db.all(sql, (error, rows) => {
if (error) {
this.logger.error(`[storage ${this.name}] each(): ${error}`);
hadError = true;
this.logger.error(`[storage ${this.name}] all(): ${error}`);
return reject(error);
}
if (!hadError) {
callback(row);
}
}, error => {
if (error) {
this.logger.error(`[storage ${this.name}] each(): ${error}`);
return reject(error);
}
return resolve();
return resolve(rows);
});
});
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册