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

storage - use all() over each()

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