sqlite: use serialize_fetchall in search

This commit is contained in:
Reto Brunner 2022-08-27 15:18:22 +02:00 committed by Reto Brunner
parent ee8223c200
commit 5e1cbe32f9

View File

@ -195,10 +195,10 @@ class SqliteMessageStorage implements ISqliteMessageStorage {
}) as Message[];
}
search(query: SearchQuery): Promise<SearchResponse> {
async search(query: SearchQuery): Promise<SearchResponse> {
if (!this.isEnabled) {
// this should never be hit as messageProvider is checked in client.search()
return Promise.reject(
throw new Error(
"search called but sqlite provider not enabled. This is a programming error"
);
}
@ -227,11 +227,7 @@ class SqliteMessageStorage implements ISqliteMessageStorage {
query.offset = parseInt(query.offset as string, 10) || 0;
params.push(String(query.offset));
return new Promise((resolve, reject) => {
this.database.all(select, params, (err, rows) => {
if (err) {
reject(err);
} else {
const rows = await this.serialize_fetchall(select, ...params);
const response: SearchResponse = {
searchTerm: query.searchTerm,
target: query.channelName,
@ -239,10 +235,8 @@ class SqliteMessageStorage implements ISqliteMessageStorage {
offset: query.offset as number,
results: parseSearchRowsToMessages(query.offset as number, rows).reverse(),
};
resolve(response);
}
});
});
return response;
}
canProvideMessages() {