From 7e5c4be14f33223bd3fa2627290d13b24553c68f Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Tue, 13 Jul 2021 17:11:11 +0100 Subject: [PATCH] fix postgres query array value --- packages/server/src/integrations/base/definitions.ts | 8 +++++--- packages/server/src/integrations/postgres.ts | 2 +- packages/server/src/integrations/tests/postgres.spec.js | 8 ++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/server/src/integrations/base/definitions.ts b/packages/server/src/integrations/base/definitions.ts index 9d5567b6c8..c202a828d0 100644 --- a/packages/server/src/integrations/base/definitions.ts +++ b/packages/server/src/integrations/base/definitions.ts @@ -99,9 +99,11 @@ export interface QueryJson { export interface SqlQuery { sql: string - bindings?: { - [key: string]: any - } + bindings?: + | string[] + | { + [key: string]: any + } } export interface QueryOptions { diff --git a/packages/server/src/integrations/postgres.ts b/packages/server/src/integrations/postgres.ts index 27286ebd02..787bce7e4e 100644 --- a/packages/server/src/integrations/postgres.ts +++ b/packages/server/src/integrations/postgres.ts @@ -92,7 +92,7 @@ module PostgresModule { async function internalQuery(client: any, query: SqlQuery) { try { - return await client.query(query.sql, query.bindings || {}) + return await client.query(query.sql, query.bindings || []) } catch (err) { throw new Error(err) } diff --git a/packages/server/src/integrations/tests/postgres.spec.js b/packages/server/src/integrations/tests/postgres.spec.js index 348fa20b6f..5d0283ec90 100644 --- a/packages/server/src/integrations/tests/postgres.spec.js +++ b/packages/server/src/integrations/tests/postgres.spec.js @@ -20,7 +20,7 @@ describe("Postgres Integration", () => { const response = await config.integration.create({ sql }) - expect(pg.queryMock).toHaveBeenCalledWith(sql, {}) + expect(pg.queryMock).toHaveBeenCalledWith(sql, []) }) it("calls the read method with the correct params", async () => { @@ -28,7 +28,7 @@ describe("Postgres Integration", () => { const response = await config.integration.read({ sql }) - expect(pg.queryMock).toHaveBeenCalledWith(sql, {}) + expect(pg.queryMock).toHaveBeenCalledWith(sql, []) }) it("calls the update method with the correct params", async () => { @@ -36,7 +36,7 @@ describe("Postgres Integration", () => { const response = await config.integration.update({ sql }) - expect(pg.queryMock).toHaveBeenCalledWith(sql, {}) + expect(pg.queryMock).toHaveBeenCalledWith(sql, []) }) it("calls the delete method with the correct params", async () => { @@ -44,7 +44,7 @@ describe("Postgres Integration", () => { await config.integration.delete({ sql }) - expect(pg.queryMock).toHaveBeenCalledWith(sql, {}) + expect(pg.queryMock).toHaveBeenCalledWith(sql, []) }) describe("no rows returned", () => {