From d2df13186525c326607b3febb34429e8531ad15c Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Mon, 3 Aug 2020 16:26:03 -0400 Subject: [PATCH 1/7] expand and unify reported version info Signed-off-by: Matthew Peveler --- spec/db.spec.js | 14 ++++++++++++-- src/db/client.js | 6 +++--- src/db/clients/mysql.js | 21 ++++++++++++++++++--- src/db/clients/postgresql.js | 8 +++++++- src/db/clients/sqlite.js | 7 ++++++- 5 files changed, 46 insertions(+), 10 deletions(-) diff --git a/spec/db.spec.js b/spec/db.spec.js index 590d1f2..278e4da 100644 --- a/spec/db.spec.js +++ b/spec/db.spec.js @@ -94,8 +94,18 @@ describe('db', () => { describe('.version', () => { it('should return a version', async () => { - expect(dbConn.version()).to.be.a('string'); - expect(dbConn.version()).to.not.be.empty; + const version = dbConn.getVersion(); + console.log(version); + expect(dbConn.getVersion()).to.be.a('object'); + const expectedName = { + postgres: 'PostgreSQL', + mysql: 'MySQL', + mariadb: 'MariaDB', + sqlite: 'SQLite', + }; + expect(version).to.have.property('name').to.contain(expectedName[dbClient]); + expect(version).to.have.property('version').to.be.a('string').and.to.match(/(?:[0-9]\.)+/); + expect(version).to.have.property('string').to.be.a('string').and.to.be.not.empty; }); }); diff --git a/src/db/client.js b/src/db/client.js index 954c16b..d6d3625 100644 --- a/src/db/client.js +++ b/src/db/client.js @@ -18,7 +18,7 @@ export function createConnection(server, database) { return { connect: connect.bind(null, server, database), disconnect: disconnect.bind(null, server, database), - version: version.bind(null, server, database), + getVersion: getVersion.bind(null, server, database), listTables: listTables.bind(null, server, database), listViews: listViews.bind(null, server, database), listRoutines: listRoutines.bind(null, server, database), @@ -120,9 +120,9 @@ function disconnect(server, database) { } } -function version(server, database) { +function getVersion(server, database) { checkIsConnected(server, database); - return database.connection.version; + return database.connection.getVersion(); } function listSchemas(server, database, filter) { diff --git a/src/db/clients/mysql.js b/src/db/clients/mysql.js index f8a0d4f..2f6a2b9 100644 --- a/src/db/clients/mysql.js +++ b/src/db/clients/mysql.js @@ -21,12 +21,27 @@ export default async function (server, database) { pool: mysql.createPool(dbConfig), }; - // light solution to test connection with with the server - const version = (await driverExecuteQuery(conn, { query: 'select version() as version;' })).data[0].version; + const versionInfo = (await driverExecuteQuery(conn, { query: "SHOW VARIABLES WHERE variable_name='version' OR variable_name='version_comment';" })).data; + const versionData = { + name: '', + version: '', + string: '', + }; + + for (let i = 0; i < versionInfo.length; i++) { + const item = versionInfo[i]; + if (item.Variable_name === 'version') { + versionData.version = item.Value; + } else if (item.Variable_name === 'version_comment') { + versionData.name = item.Value; + } + } + versionData.string = `${versionData.name} ${versionData.version}`; + versionData.version = versionData.version.split('-')[0]; return { wrapIdentifier, - version, + getVersion: () => versionData, disconnect: () => disconnect(conn), listTables: () => listTables(conn), listViews: () => listViews(conn), diff --git a/src/db/clients/postgresql.js b/src/db/clients/postgresql.js index 09c064c..ca6b1cf 100644 --- a/src/db/clients/postgresql.js +++ b/src/db/clients/postgresql.js @@ -34,11 +34,17 @@ export default async function (server, database) { const defaultSchema = await getSchema(conn); const version = (await driverExecuteQuery(conn, { query: 'select version()' })).rows[0].version; + const splitVersion = version.split(' '); + const versionDetails = { + name: splitVersion[0], + version: splitVersion[1], + string: version, + }; return { /* eslint max-len:0 */ wrapIdentifier, - version, + getVersion: () => versionDetails, disconnect: () => disconnect(conn), listTables: (db, filter) => listTables(conn, filter), listViews: (filter) => listViews(conn, filter), diff --git a/src/db/clients/sqlite.js b/src/db/clients/sqlite.js index 149f902..e9a61bb 100644 --- a/src/db/clients/sqlite.js +++ b/src/db/clients/sqlite.js @@ -18,10 +18,15 @@ export default async function (server, database) { // light solution to test connection with with the server const version = (await driverExecuteQuery(conn, { query: 'SELECT sqlite_version() as version' })).data[0].version; + const versionData = { + name: 'SQLite', + version, + string: `SQLite ${version}`, + }; return { wrapIdentifier, - version, + getVersion: () => versionData, disconnect: () => disconnect(conn), listTables: () => listTables(conn), listViews: () => listViews(conn), From 7247583ccc407c6257a31a8ce019c77735e9aa3e Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Tue, 4 Aug 2020 16:06:21 -0400 Subject: [PATCH 2/7] continue work Signed-off-by: Matthew Peveler --- spec/db.spec.js | 9 ++++++++- src/db/client.js | 9 +++++++++ src/db/clients/cassandra.js | 9 +++++---- src/db/clients/mysql.js | 1 + src/db/clients/postgresql.js | 1 + src/db/clients/sqlite.js | 1 + src/db/clients/sqlserver.js | 1 + 7 files changed, 26 insertions(+), 5 deletions(-) diff --git a/spec/db.spec.js b/spec/db.spec.js index 72af6b5..c8b9567 100644 --- a/spec/db.spec.js +++ b/spec/db.spec.js @@ -93,7 +93,14 @@ describe('db', () => { }); describe('.version', () => { - it('should return a version', async () => { + it('should return version string', () => { + const version = dbConn.version(); + expect(version).to.be.a.string.and.not.be.empty; + }); + }); + + describe('.getVersion', () => { + it('should return version details', () => { const version = dbConn.getVersion(); console.log(version); expect(dbConn.getVersion()).to.be.a('object'); diff --git a/src/db/client.js b/src/db/client.js index d6d3625..5ea1ecb 100644 --- a/src/db/client.js +++ b/src/db/client.js @@ -18,6 +18,7 @@ export function createConnection(server, database) { return { connect: connect.bind(null, server, database), disconnect: disconnect.bind(null, server, database), + version: version.bind(null, server, database), getVersion: getVersion.bind(null, server, database), listTables: listTables.bind(null, server, database), listViews: listViews.bind(null, server, database), @@ -120,6 +121,14 @@ function disconnect(server, database) { } } +/** + * @deprecated + */ +function version(server, database) { + checkIsConnected(server, database); + return database.connection.version; +} + function getVersion(server, database) { checkIsConnected(server, database); return database.connection.getVersion(); diff --git a/src/db/clients/cassandra.js b/src/db/clients/cassandra.js index 1078b9e..06b0c12 100644 --- a/src/db/clients/cassandra.js +++ b/src/db/clients/cassandra.js @@ -23,12 +23,13 @@ export default function (server, database) { return reject(err); } - client.version = client.getState().getConnectedHosts()[0].cassandraVersion; + client.version = client.getState().getConnectedHosts()[0].getCassandraVersion(); logger().debug('connected'); resolve({ wrapIdentifier, - version: client.version, + version: client.getState().getConnectedHosts()[0].cassandraVersion, + getVersion: () => client.getState().getConnectedHosts()[0].cassandraVersion, disconnect: () => disconnect(client), listTables: (db) => listTables(client, db), listViews: () => listViews(client), @@ -60,7 +61,7 @@ export function disconnect(client) { export function listTables(client, database) { return new Promise((resolve, reject) => { let sql; - if (client.version.split('.')[0] === '2') { + if (client.version[0] === 2) { sql = ` SELECT columnfamily_name as name FROM system.schema_columnfamilies @@ -91,7 +92,7 @@ export function listRoutines() { } export function listTableColumns(client, database, table) { - const cassandra2 = client.version.split('.')[0] === '2'; + const cassandra2 = client.version[0] === 2; return new Promise((resolve, reject) => { let sql; if (cassandra2) { diff --git a/src/db/clients/mysql.js b/src/db/clients/mysql.js index 2f6a2b9..914e281 100644 --- a/src/db/clients/mysql.js +++ b/src/db/clients/mysql.js @@ -41,6 +41,7 @@ export default async function (server, database) { return { wrapIdentifier, + version: versionData.version, getVersion: () => versionData, disconnect: () => disconnect(conn), listTables: () => listTables(conn), diff --git a/src/db/clients/postgresql.js b/src/db/clients/postgresql.js index ca6b1cf..7a4ae8d 100644 --- a/src/db/clients/postgresql.js +++ b/src/db/clients/postgresql.js @@ -44,6 +44,7 @@ export default async function (server, database) { return { /* eslint max-len:0 */ wrapIdentifier, + version, getVersion: () => versionDetails, disconnect: () => disconnect(conn), listTables: (db, filter) => listTables(conn, filter), diff --git a/src/db/clients/sqlite.js b/src/db/clients/sqlite.js index e9a61bb..df5dae6 100644 --- a/src/db/clients/sqlite.js +++ b/src/db/clients/sqlite.js @@ -26,6 +26,7 @@ export default async function (server, database) { return { wrapIdentifier, + version, getVersion: () => versionData, disconnect: () => disconnect(conn), listTables: () => listTables(conn), diff --git a/src/db/clients/sqlserver.js b/src/db/clients/sqlserver.js index 940d2bd..35bf721 100644 --- a/src/db/clients/sqlserver.js +++ b/src/db/clients/sqlserver.js @@ -23,6 +23,7 @@ export default async function (server, database) { return { wrapIdentifier, version, + getVersion: () => version, disconnect: () => disconnect(conn), listTables: (db, filter) => listTables(conn, filter), listViews: (filter) => listViews(conn, filter), From 314465b159c59b090ee6e1d1e2c22f74801402e1 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Tue, 4 Aug 2020 16:39:12 -0400 Subject: [PATCH 3/7] finish up work on getVersion Signed-off-by: Matthew Peveler --- spec/db.spec.js | 14 ++++++------- src/db/clients/cassandra.js | 8 +++++++- src/db/clients/mysql.js | 40 +++++++++++++++++++++++++++---------- src/db/clients/sqlserver.js | 8 +++++++- 4 files changed, 50 insertions(+), 20 deletions(-) diff --git a/spec/db.spec.js b/spec/db.spec.js index c8b9567..1981f2e 100644 --- a/spec/db.spec.js +++ b/spec/db.spec.js @@ -4,6 +4,7 @@ import { db } from '../src'; import config from './databases/config'; import setupSQLite from './databases/sqlite/setup'; import setupCassandra from './databases/cassandra/setup'; +import { versionCompare } from '../src/utils'; chai.use(chaiAsPromised); @@ -102,7 +103,6 @@ describe('db', () => { describe('.getVersion', () => { it('should return version details', () => { const version = dbConn.getVersion(); - console.log(version); expect(dbConn.getVersion()).to.be.a('object'); const expectedName = { postgres: 'PostgreSQL', @@ -328,7 +328,7 @@ describe('db', () => { it('should return table create script', async () => { const [createScript] = await dbConn.getTableCreateScript('users'); - if (dbClient === 'mysql' && parseInt(dbConn.version()[0], 10) >= '8') { + if (dbClient === 'mysql' && versionCompare(dbConn.getVersion().version, '8') >= 0) { expect(createScript).to.contain('CREATE TABLE `users` (\n' + ' `id` int NOT NULL AUTO_INCREMENT,\n' + ' `username` varchar(45) DEFAULT NULL,\n' + @@ -706,7 +706,7 @@ describe('db', () => { } } catch (err) { if (dbClient === 'cassandra') { - if (dbConn.version().split('.')[0] === '2') { + if (versionCompare(dbConn.getVersion().version, '2') === 0) { expect(err.message).to.eql('line 0:-1 no viable alternative at input \'\''); } else { expect(err.message).to.eql('line 1:13 mismatched character \'\' expecting set null'); @@ -811,7 +811,7 @@ describe('db', () => { expect(secondResult).to.have.deep.property('rowCount').to.eql(1); } catch (err) { if (dbClient === 'cassandra') { - if (parseFloat(dbConn.version().split('.').slice(0, 2).join('.')) >= 3.10) { + if (versionCompare(dbConn.getVersion().version, '3.10') >= 0) { expect(err.message).to.match(/mismatched input 'select' expecting EOF/); } else { expect(err.message).to.match(/missing EOF at 'select'/); @@ -891,7 +891,7 @@ describe('db', () => { } } catch (err) { if (dbClient === 'cassandra') { - if (parseFloat(dbConn.version().split('.').slice(0, 2).join('.')) >= 3.10) { + if (versionCompare(dbConn.getVersion().version, '3.10') >= 0) { expect(err.message).to.match(/mismatched input 'insert' expecting EOF/); } else { expect(err.message).to.match(/missing EOF at 'insert'/); @@ -967,7 +967,7 @@ describe('db', () => { } } catch (err) { if (dbClient === 'cassandra') { - if (parseFloat(dbConn.version().split('.').slice(0, 2).join('.')) >= 3.10) { + if (versionCompare(dbConn.getVersion().version, '3.10') >= 0) { expect(err.message).to.match(/mismatched input 'delete' expecting EOF/); } else { expect(err.message).to.match(/missing EOF at 'delete'/); @@ -1043,7 +1043,7 @@ describe('db', () => { } } catch (err) { if (dbClient === 'cassandra') { - if (parseFloat(dbConn.version().split('.').slice(0, 2).join('.')) >= 3.10) { + if (versionCompare(dbConn.version().version, '3.10') >= 0) { expect(err.message).to.match(/mismatched input 'update' expecting EOF/); } else { expect(err.message).to.match(/missing EOF at 'update'/); diff --git a/src/db/clients/cassandra.js b/src/db/clients/cassandra.js index 06b0c12..f9c1222 100644 --- a/src/db/clients/cassandra.js +++ b/src/db/clients/cassandra.js @@ -25,11 +25,17 @@ export default function (server, database) { client.version = client.getState().getConnectedHosts()[0].getCassandraVersion(); + const versionData = { + name: 'Cassandra', + version: client.getState().getConnectedHosts()[0].cassandraVersion, + string: `Cassandra ${client.getState().getConnectedHosts()[0].cassandraVersion}`, + }; + logger().debug('connected'); resolve({ wrapIdentifier, version: client.getState().getConnectedHosts()[0].cassandraVersion, - getVersion: () => client.getState().getConnectedHosts()[0].cassandraVersion, + getVersion: () => versionData, disconnect: () => disconnect(client), listTables: (db) => listTables(client, db), listViews: () => listViews(client), diff --git a/src/db/clients/mysql.js b/src/db/clients/mysql.js index 914e281..b908564 100644 --- a/src/db/clients/mysql.js +++ b/src/db/clients/mysql.js @@ -21,23 +21,38 @@ export default async function (server, database) { pool: mysql.createPool(dbConfig), }; - const versionInfo = (await driverExecuteQuery(conn, { query: "SHOW VARIABLES WHERE variable_name='version' OR variable_name='version_comment';" })).data; - const versionData = { - name: '', - version: '', - string: '', - }; + const versionInfo = (await driverExecuteQuery(conn, { + query: "SHOW VARIABLES WHERE variable_name='version' OR variable_name='version_comment';", + })).data; + let version; + let versionComment; for (let i = 0; i < versionInfo.length; i++) { const item = versionInfo[i]; if (item.Variable_name === 'version') { - versionData.version = item.Value; + version = item.Value; } else if (item.Variable_name === 'version_comment') { - versionData.name = item.Value; + versionComment = item.Value; } } - versionData.string = `${versionData.name} ${versionData.version}`; - versionData.version = versionData.version.split('-')[0]; + + const versionData = { + name: versionComment, + version: version.split('-')[0], + string: `${versionComment} ${version}`, + }; + + // normalize the name as depending on where the server is installed from, it + // could be just "MySQL" or "MariaDB", or it could be a longer string like + // "mariadb.org binary distribution" + const lowerComment = versionComment.toLowerCase(); + if (lowerComment.includes('mysql')) { + versionData.name = 'MySQL'; + } else if (lowerComment.includes('mariadb')) { + versionData.name = 'MariaDB'; + } else if (lowerComment.includes('percona')) { + versionData.name = 'Percona'; + } return { wrapIdentifier, @@ -188,7 +203,10 @@ export async function getTableReferences(conn, table) { export async function getTableKeys(conn, database, table) { const sql = ` - SELECT constraint_name as 'constraint_name', column_name as 'column_name', referenced_table_name as 'referenced_table_name', + SELECT + constraint_name as 'constraint_name', + column_name as 'column_name', + referenced_table_name as 'referenced_table_name', CASE WHEN (referenced_table_name IS NOT NULL) THEN 'FOREIGN' ELSE constraint_name END as key_type diff --git a/src/db/clients/sqlserver.js b/src/db/clients/sqlserver.js index 35bf721..8be56a3 100644 --- a/src/db/clients/sqlserver.js +++ b/src/db/clients/sqlserver.js @@ -20,10 +20,16 @@ export default async function (server, database) { // light solution to test connection with with the server const version = (await driverExecuteQuery(conn, { query: 'SELECT @@version as \'version\'' })).data[0].version; + const versionData = { + name: 'SQL Server', + version: version.match(/^Microsoft SQL Server ([0-9]{4})/)[1], + string: version, + }; + return { wrapIdentifier, version, - getVersion: () => version, + getVersion: () => versionData, disconnect: () => disconnect(conn), listTables: (db, filter) => listTables(conn, filter), listViews: (filter) => listViews(conn, filter), From 38832cf391d19c264ab55fd7369fee64008adc2c Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Tue, 4 Aug 2020 16:40:28 -0400 Subject: [PATCH 4/7] add missing two adapters Signed-off-by: Matthew Peveler --- spec/db.spec.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/db.spec.js b/spec/db.spec.js index 1981f2e..0d7984b 100644 --- a/spec/db.spec.js +++ b/spec/db.spec.js @@ -109,6 +109,8 @@ describe('db', () => { mysql: 'MySQL', mariadb: 'MariaDB', sqlite: 'SQLite', + sqlserver: 'SQL Server', + cassandra: 'Cassandra', }; expect(version).to.have.property('name').to.contain(expectedName[dbClient]); expect(version).to.have.property('version').to.be.a('string').and.to.match(/(?:[0-9]\.)+/); From bbb57af477d666bdd5e55375aeba203f915a0f6a Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Tue, 4 Aug 2020 16:45:05 -0400 Subject: [PATCH 5/7] fix broken expect chain Signed-off-by: Matthew Peveler --- spec/db.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/db.spec.js b/spec/db.spec.js index 0d7984b..4b93ddb 100644 --- a/spec/db.spec.js +++ b/spec/db.spec.js @@ -96,7 +96,7 @@ describe('db', () => { describe('.version', () => { it('should return version string', () => { const version = dbConn.version(); - expect(version).to.be.a.string.and.not.be.empty; + expect(version).to.be.a('string').and.not.be.empty; }); }); From 82e4caf0bccc29a0b105ed428344ed657a0cbb8e Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Tue, 4 Aug 2020 16:51:53 -0400 Subject: [PATCH 6/7] fix failing tests Signed-off-by: Matthew Peveler --- spec/db.spec.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/db.spec.js b/spec/db.spec.js index 4b93ddb..e6f0eef 100644 --- a/spec/db.spec.js +++ b/spec/db.spec.js @@ -105,7 +105,7 @@ describe('db', () => { const version = dbConn.getVersion(); expect(dbConn.getVersion()).to.be.a('object'); const expectedName = { - postgres: 'PostgreSQL', + postgresql: 'PostgreSQL', mysql: 'MySQL', mariadb: 'MariaDB', sqlite: 'SQLite', @@ -113,7 +113,7 @@ describe('db', () => { cassandra: 'Cassandra', }; expect(version).to.have.property('name').to.contain(expectedName[dbClient]); - expect(version).to.have.property('version').to.be.a('string').and.to.match(/(?:[0-9]\.)+/); + expect(version).to.have.property('version').to.be.a('string').and.to.match(/(?:[0-9]\.?)+/); expect(version).to.have.property('string').to.be.a('string').and.to.be.not.empty; }); }); @@ -1045,7 +1045,7 @@ describe('db', () => { } } catch (err) { if (dbClient === 'cassandra') { - if (versionCompare(dbConn.version().version, '3.10') >= 0) { + if (versionCompare(dbConn.getVersion().version, '3.10') >= 0) { expect(err.message).to.match(/mismatched input 'update' expecting EOF/); } else { expect(err.message).to.match(/missing EOF at 'update'/); From 6ed98c63df06d038dfaaaa65da210e52b96fe052 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Tue, 4 Aug 2020 17:03:00 -0400 Subject: [PATCH 7/7] unify versionData to be on conn object Signed-off-by: Matthew Peveler --- src/db/clients/cassandra.js | 4 ++-- src/db/clients/mysql.js | 12 ++++++------ src/db/clients/postgresql.js | 5 +++-- src/db/clients/sqlite.js | 4 ++-- src/db/clients/sqlserver.js | 4 ++-- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/db/clients/cassandra.js b/src/db/clients/cassandra.js index f9c1222..af58b09 100644 --- a/src/db/clients/cassandra.js +++ b/src/db/clients/cassandra.js @@ -25,7 +25,7 @@ export default function (server, database) { client.version = client.getState().getConnectedHosts()[0].getCassandraVersion(); - const versionData = { + client.versionData = { name: 'Cassandra', version: client.getState().getConnectedHosts()[0].cassandraVersion, string: `Cassandra ${client.getState().getConnectedHosts()[0].cassandraVersion}`, @@ -35,7 +35,7 @@ export default function (server, database) { resolve({ wrapIdentifier, version: client.getState().getConnectedHosts()[0].cassandraVersion, - getVersion: () => versionData, + getVersion: () => client.versionData, disconnect: () => disconnect(client), listTables: (db) => listTables(client, db), listViews: () => listViews(client), diff --git a/src/db/clients/mysql.js b/src/db/clients/mysql.js index b908564..f3e4c6c 100644 --- a/src/db/clients/mysql.js +++ b/src/db/clients/mysql.js @@ -36,7 +36,7 @@ export default async function (server, database) { } } - const versionData = { + conn.versionData = { name: versionComment, version: version.split('-')[0], string: `${versionComment} ${version}`, @@ -47,17 +47,17 @@ export default async function (server, database) { // "mariadb.org binary distribution" const lowerComment = versionComment.toLowerCase(); if (lowerComment.includes('mysql')) { - versionData.name = 'MySQL'; + conn.versionData.name = 'MySQL'; } else if (lowerComment.includes('mariadb')) { - versionData.name = 'MariaDB'; + conn.versionData.name = 'MariaDB'; } else if (lowerComment.includes('percona')) { - versionData.name = 'Percona'; + conn.versionData.name = 'Percona'; } return { wrapIdentifier, - version: versionData.version, - getVersion: () => versionData, + version: conn.versionData.version, + getVersion: () => conn.versionData, disconnect: () => disconnect(conn), listTables: () => listTables(conn), listViews: () => listViews(conn), diff --git a/src/db/clients/postgresql.js b/src/db/clients/postgresql.js index 7a4ae8d..144077d 100644 --- a/src/db/clients/postgresql.js +++ b/src/db/clients/postgresql.js @@ -35,7 +35,8 @@ export default async function (server, database) { const version = (await driverExecuteQuery(conn, { query: 'select version()' })).rows[0].version; const splitVersion = version.split(' '); - const versionDetails = { + + conn.versionData = { name: splitVersion[0], version: splitVersion[1], string: version, @@ -45,7 +46,7 @@ export default async function (server, database) { /* eslint max-len:0 */ wrapIdentifier, version, - getVersion: () => versionDetails, + getVersion: () => conn.versionData, disconnect: () => disconnect(conn), listTables: (db, filter) => listTables(conn, filter), listViews: (filter) => listViews(conn, filter), diff --git a/src/db/clients/sqlite.js b/src/db/clients/sqlite.js index df5dae6..e656a6d 100644 --- a/src/db/clients/sqlite.js +++ b/src/db/clients/sqlite.js @@ -18,7 +18,7 @@ export default async function (server, database) { // light solution to test connection with with the server const version = (await driverExecuteQuery(conn, { query: 'SELECT sqlite_version() as version' })).data[0].version; - const versionData = { + conn.versionData = { name: 'SQLite', version, string: `SQLite ${version}`, @@ -27,7 +27,7 @@ export default async function (server, database) { return { wrapIdentifier, version, - getVersion: () => versionData, + getVersion: () => conn.versionData, disconnect: () => disconnect(conn), listTables: () => listTables(conn), listViews: () => listViews(conn), diff --git a/src/db/clients/sqlserver.js b/src/db/clients/sqlserver.js index 8be56a3..3024e7c 100644 --- a/src/db/clients/sqlserver.js +++ b/src/db/clients/sqlserver.js @@ -20,7 +20,7 @@ export default async function (server, database) { // light solution to test connection with with the server const version = (await driverExecuteQuery(conn, { query: 'SELECT @@version as \'version\'' })).data[0].version; - const versionData = { + conn.versionData = { name: 'SQL Server', version: version.match(/^Microsoft SQL Server ([0-9]{4})/)[1], string: version, @@ -29,7 +29,7 @@ export default async function (server, database) { return { wrapIdentifier, version, - getVersion: () => versionData, + getVersion: () => conn.versionData, disconnect: () => disconnect(conn), listTables: (db, filter) => listTables(conn, filter), listViews: (filter) => listViews(conn, filter),