From effe53807a95fd70f17b6dfcfdae94c9bd2f8761 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Thu, 3 Feb 2022 13:26:42 +0100 Subject: [PATCH] MOBILE-3977 db: Implement method to log history --- src/core/services/db.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/core/services/db.ts b/src/core/services/db.ts index 727b5424d..489d44072 100644 --- a/src/core/services/db.ts +++ b/src/core/services/db.ts @@ -38,6 +38,17 @@ export class CoreDbProvider { return CoreAppProvider.isAutomated(); } + /** + * Print query history in console. + */ + printHistory(): void { + const substituteParams = ({ sql, params }: CoreDbQueryLog) => + Object.values(params ?? []).reduce((sql: string, param: string) => sql.replace('?', param), sql); + + // eslint-disable-next-line no-console + console.log(this.queryLogs.map(substituteParams).join('\n')); + } + /** * Log a query. *