From 34d58f9e9e6ee2a7eb967da9772ccf4d8f9f110a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric=20Moreau?= <cem.moreau@gmail.com>
Date: Sat, 7 Apr 2018 13:55:32 +0200
Subject: [PATCH] [enh] Add `--sql-traces` option

---
 app/lib/dal/drivers/SQLiteDriver.ts | 7 +++++++
 app/lib/other_constants.ts          | 1 +
 index.ts                            | 4 +++-
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/app/lib/dal/drivers/SQLiteDriver.ts b/app/lib/dal/drivers/SQLiteDriver.ts
index b7e52b00e..c0ce0cba0 100644
--- a/app/lib/dal/drivers/SQLiteDriver.ts
+++ b/app/lib/dal/drivers/SQLiteDriver.ts
@@ -11,6 +11,8 @@
 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 // GNU Affero General Public License for more details.
 
+import {OtherConstants} from "../../other_constants"
+
 const qfs     = require('q-io/fs')
 const sqlite3 = require("sqlite3").verbose()
 
@@ -34,6 +36,11 @@ export class SQLiteDriver {
         let sqlite = new sqlite3.Database(this.path)
         await new Promise<any>((resolve) => sqlite.once('open', resolve))
         // Database is opened
+        if (OtherConstants.SQL_TRACES) {
+          sqlite.on('trace', (trace:any) => {
+            this.logger.trace(trace)
+          })
+        }
 
         // Force case sensitiveness on LIKE operator
         const sql = 'PRAGMA case_sensitive_like=ON'
diff --git a/app/lib/other_constants.ts b/app/lib/other_constants.ts
index 203afe23d..63162b599 100644
--- a/app/lib/other_constants.ts
+++ b/app/lib/other_constants.ts
@@ -14,6 +14,7 @@
 export const OtherConstants = {
 
   MUTE_LOGS_DURING_UNIT_TESTS: true,
+  SQL_TRACES: false,
 
   BC_EVENT: {
     SWITCHED: 'switched',
diff --git a/index.ts b/index.ts
index 646e2bf6d..d28736977 100644
--- a/index.ts
+++ b/index.ts
@@ -21,8 +21,9 @@ import {CrawlerDependency} from "./app/modules/crawler/index"
 import {BmaDependency} from "./app/modules/bma/index"
 import {WS2PDependency} from "./app/modules/ws2p/index"
 import {ProverConstants} from "./app/modules/prover/lib/constants"
-import { ProxiesConf } from './app/lib/proxy';
+import {ProxiesConf} from './app/lib/proxy';
 import {RouterDependency} from "./app/modules/router"
+import {OtherConstants} from "./app/lib/other_constants"
 
 const path = require('path');
 const _ = require('underscore');
@@ -288,6 +289,7 @@ class Stack {
     const params  = args.slice(2);
     params.pop(); // Don't need the command argument
 
+    OtherConstants.SQL_TRACES = program.sqlTraces === true
     const dbName = program.mdb;
     const dbHome = program.home;
     const home = directory.getHome(dbName, dbHome);
-- 
GitLab