Browse Source

fix postgres query array value

gh-pages
Martin McKeaveney 5 years ago
parent
commit
eba8f104fd
  1. 4
      packages/server/src/integrations/base/definitions.ts
  2. 2
      packages/server/src/integrations/postgres.ts
  3. 8
      packages/server/src/integrations/tests/postgres.spec.js

4
packages/server/src/integrations/base/definitions.ts

@ -99,7 +99,9 @@ export interface QueryJson {
export interface SqlQuery { export interface SqlQuery {
sql: string sql: string
bindings?: { bindings?:
| string[]
| {
[key: string]: any [key: string]: any
} }
} }

2
packages/server/src/integrations/postgres.ts

@ -92,7 +92,7 @@ module PostgresModule {
async function internalQuery(client: any, query: SqlQuery) { async function internalQuery(client: any, query: SqlQuery) {
try { try {
return await client.query(query.sql, query.bindings || {}) return await client.query(query.sql, query.bindings || [])
} catch (err) { } catch (err) {
throw new Error(err) throw new Error(err)
} }

8
packages/server/src/integrations/tests/postgres.spec.js

@ -20,7 +20,7 @@ describe("Postgres Integration", () => {
const response = await config.integration.create({ const response = await config.integration.create({
sql sql
}) })
expect(pg.queryMock).toHaveBeenCalledWith(sql, {}) expect(pg.queryMock).toHaveBeenCalledWith(sql, [])
}) })
it("calls the read method with the correct params", async () => { it("calls the read method with the correct params", async () => {
@ -28,7 +28,7 @@ describe("Postgres Integration", () => {
const response = await config.integration.read({ const response = await config.integration.read({
sql sql
}) })
expect(pg.queryMock).toHaveBeenCalledWith(sql, {}) expect(pg.queryMock).toHaveBeenCalledWith(sql, [])
}) })
it("calls the update method with the correct params", async () => { it("calls the update method with the correct params", async () => {
@ -36,7 +36,7 @@ describe("Postgres Integration", () => {
const response = await config.integration.update({ const response = await config.integration.update({
sql sql
}) })
expect(pg.queryMock).toHaveBeenCalledWith(sql, {}) expect(pg.queryMock).toHaveBeenCalledWith(sql, [])
}) })
it("calls the delete method with the correct params", async () => { it("calls the delete method with the correct params", async () => {
@ -44,7 +44,7 @@ describe("Postgres Integration", () => {
await config.integration.delete({ await config.integration.delete({
sql sql
}) })
expect(pg.queryMock).toHaveBeenCalledWith(sql, {}) expect(pg.queryMock).toHaveBeenCalledWith(sql, [])
}) })
describe("no rows returned", () => { describe("no rows returned", () => {

Loading…
Cancel
Save