Skip to content

Commit

Permalink
query-transformer (postgres): fix simple-array when value is empty (#133
Browse files Browse the repository at this point in the history
) (#134)
  • Loading branch information
dpecos authored Mar 31, 2022
1 parent e1040e0 commit 3009530
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/query-transformer/postgres-query-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export class PostgresQueryTransformer extends QueryTransformer {
return parameter
}

if (typeof parameter === 'object' && parameter?.value) {
if (typeof parameter === 'object' && typeof parameter?.value !== 'undefined') {
return ({
name: `param_${index + 1}`,
...parameter,
Expand Down
19 changes: 19 additions & 0 deletions test/functional/pg/basic/simple-queries.pg-func.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,25 @@ describe('aurora data api pg > simple queries', () => {
})
})

it('should handle empty simple-array', async () => {
await useCleanDatabase('postgres', { entities: [SimpleArrayEntity] }, async (connection) => {
const simpleArrayEntity = new SimpleArrayEntity()

simpleArrayEntity.array = []

const newSimpleArrayEntity = await connection.getRepository(SimpleArrayEntity).save(simpleArrayEntity)

const loadedSimpleArrayEntity = (await connection.getRepository(SimpleArrayEntity).findOne(newSimpleArrayEntity.id))!

// Assert
expect(newSimpleArrayEntity).toBeTruthy()
expect(newSimpleArrayEntity.array).toEqual([])

expect(loadedSimpleArrayEntity).toBeTruthy()
expect(loadedSimpleArrayEntity.array).toEqual([])
})
})


it('should handle null values', async () => {
await useCleanDatabase('postgres', { entities: [JsonEntity] }, async (connection) => {
Expand Down

0 comments on commit 3009530

Please sign in to comment.