From f507daa46a259892dda9b110be1458150adf4b97 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 3 Jun 2021 16:45:43 +0100 Subject: [PATCH] Linking up to existing SQL integrations. --- .../server/src/integrations/microsoftSqlServer.js | 4 +++- packages/server/src/integrations/mysql.js | 4 +++- packages/server/src/integrations/postgres.js | 4 +++- packages/server/src/integrations/tests/sql.spec.js | 12 +++++++++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/server/src/integrations/microsoftSqlServer.js b/packages/server/src/integrations/microsoftSqlServer.js index 3dc5676e94..bece6678a3 100644 --- a/packages/server/src/integrations/microsoftSqlServer.js +++ b/packages/server/src/integrations/microsoftSqlServer.js @@ -1,5 +1,6 @@ const sqlServer = require("mssql") const { FIELD_TYPES } = require("./Integration") +const Sql = require("./base/sql") const SCHEMA = { docs: "https://github.com/tediousjs/node-mssql", @@ -50,10 +51,11 @@ const SCHEMA = { }, } -class SqlServerIntegration { +class SqlServerIntegration extends Sql { static pool constructor(config) { + super("mssql") this.config = config this.config.options = { encrypt: this.config.encrypt, diff --git a/packages/server/src/integrations/mysql.js b/packages/server/src/integrations/mysql.js index c505c4fc14..6c72e05a12 100644 --- a/packages/server/src/integrations/mysql.js +++ b/packages/server/src/integrations/mysql.js @@ -1,5 +1,6 @@ const mysql = require("mysql") const { FIELD_TYPES, QUERY_TYPES } = require("./Integration") +const Sql = require("./base/sql") const SCHEMA = { docs: "https://github.com/mysqljs/mysql", @@ -52,8 +53,9 @@ const SCHEMA = { }, } -class MySQLIntegration { +class MySQLIntegration extends Sql { constructor(config) { + super("mysql") this.config = config if (Object.keys(config.ssl).length === 0) { delete config.ssl diff --git a/packages/server/src/integrations/postgres.js b/packages/server/src/integrations/postgres.js index ebc39a31a4..2a39a91c2d 100644 --- a/packages/server/src/integrations/postgres.js +++ b/packages/server/src/integrations/postgres.js @@ -1,5 +1,6 @@ const { Pool } = require("pg") const { FIELD_TYPES } = require("./Integration") +const Sql = require("./base/sql") const SCHEMA = { docs: "https://node-postgres.com", @@ -54,10 +55,11 @@ const SCHEMA = { }, } -class PostgresIntegration { +class PostgresIntegration extends Sql { static pool constructor(config) { + super("pg") this.config = config if (this.config.ssl) { this.config.ssl = { diff --git a/packages/server/src/integrations/tests/sql.spec.js b/packages/server/src/integrations/tests/sql.spec.js index 98a7286c8d..c6a0debcdc 100644 --- a/packages/server/src/integrations/tests/sql.spec.js +++ b/packages/server/src/integrations/tests/sql.spec.js @@ -117,4 +117,14 @@ describe("SQL query builder", () => { })) expect(query).toEqual(`delete from "${TABLE_NAME}" where "id" = 1001`) }) -}) \ No newline at end of file + + it("should work with MS-SQL", () => { + const query = new Sql("mssql", 10).buildQuery(generateReadJson()) + expect(query).toEqual(`select top (10) * from [${TABLE_NAME}]`) + }) + + it("should work with mySQL", () => { + const query = new Sql("mysql", 10).buildQuery(generateReadJson()) + expect(query).toEqual(`select * from \`${TABLE_NAME}\` limit 10`) + }) +})