From d86090e60c4a1e7496f8636a9bfce765bac6b87a Mon Sep 17 00:00:00 2001 From: Muhammad Aaqil Date: Sun, 3 Mar 2024 21:30:03 +0500 Subject: [PATCH] feat: add query execution for mode discovery Signed-off-by: Muhammad Aaqil --- lib/sql.js | 17 +++++++++++++++++ test/connectors/test-sql-connector.js | 4 ++++ test/sql.test.js | 19 +++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/lib/sql.js b/lib/sql.js index 65a0b098..67bbd88f 100644 --- a/lib/sql.js +++ b/lib/sql.js @@ -2182,3 +2182,20 @@ SQLConnector.prototype.discoverUniqueKeys = function(table, options, cb) { const sql = self.buildQueryUniqueKeys(schema, table); this.execute(sql, cb); }; + +/** + * Discover if database is in strict mode + * @param {Function} [cb] The callback function + */ +SQLConnector.prototype.discoverIsStrict = function(cb) { + const self = this; + const sql = self.buildQueryIsStrict(); + this.execute(sql, cb); +}; + +/** + * Build sql for checking if database is in strict mode + */ +SQLConnector.prototype.buildQueryIsStrict = function() { + throw new Error(g.f('{{isStrict}} must be implemented by the connector')); +}; diff --git a/test/connectors/test-sql-connector.js b/test/connectors/test-sql-connector.js index bc86609c..573ef4e7 100644 --- a/test/connectors/test-sql-connector.js +++ b/test/connectors/test-sql-connector.js @@ -262,3 +262,7 @@ TestConnector.prototype.executeSQL = function(sql, params, options, callback) { callback(null, result); } }; + +TestConnector.prototype.buildQueryIsStrict = function() { + return 'SELECT 1 AS globalStrictMode, 1 AS sessionStrictMode'; +}; diff --git a/test/sql.test.js b/test/sql.test.js index 213b47b7..0be13918 100644 --- a/test/sql.test.js +++ b/test/sql.test.js @@ -667,4 +667,23 @@ describe('sql connector', function() { }); }); }); + + it( + 'should throw an error if buildQueryIsStrict is not implemented by SQLconnector', + function() { + const baseConnector = new SQLConnector(); + expect(function() { + baseConnector.buildQueryIsStrict(); + }).to.throw('isStrict must be implemented by the connector'); + }, + ); + + it('should support discoverIsStrict method', function(done) { + connector.discoverIsStrict(function(err, data) { + // eslint-disable-next-line no-unused-expressions + expect(err).to.be.null; + expect(data).to.be.an('array'); + done(err); + }); + }); });