Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pg): handle pg engine lowercase typeName #117

Open
wants to merge 1 commit into
base: aws-sdk-v3-migration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,16 +358,18 @@ const formatRecords = (recs, columns, hydrate, formatOptions) => {

// Format record value based on its value, the database column's typeName and the formatting options
const formatRecordValue = (value, typeName, formatOptions) => {
const standardizedTypeName = typeName ? typeName.toUpperCase() : typeName

if (
formatOptions &&
formatOptions.deserializeDate &&
['DATE', 'DATETIME', 'TIMESTAMP', 'TIMESTAMPTZ', 'TIMESTAMP WITH TIME ZONE'].includes(typeName.toUpperCase())
['DATE', 'DATETIME', 'TIMESTAMP', 'TIMESTAMPTZ', 'TIMESTAMP WITH TIME ZONE'].includes(standardizedTypeName)
) {
return formatFromTimeStamp(
value,
(formatOptions && formatOptions.treatAsLocalDate) || typeName === 'TIMESTAMP WITH TIME ZONE'
(formatOptions && formatOptions.treatAsLocalDate) || standardizedTypeName === 'TIMESTAMP WITH TIME ZONE'
)
} else if (typeName === 'JSON') {
} else if (standardizedTypeName === 'JSON') {
return JSON.parse(value)
} else {
return value
Expand Down
28 changes: 28 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,34 @@ describe('querying', () => {
[ 2, 'Category 2', 'Description of Category 2', '2019-11-12 22:17:11', '2019-11-12 22:21:36', null ]
])
})

test('with pg lowercase typeName', async () => {
let { records, columnMetadata } = require('./test/sample-query-response.json')

columnMetadata.forEach(metadata => {
metadata.typeName = metadata.typeName.toLowerCase()
})

let result = formatRecords(records, columnMetadata, true)
expect(result).toEqual([
{
created: '2019-11-12 22:00:11',
deleted: null,
description: null,
id: 1,
modified: '2019-11-12 22:15:25',
name: 'Category 1'
},
{
created: '2019-11-12 22:17:11',
deleted: null,
description: 'Description of Category 2',
id: 2,
modified: '2019-11-12 22:21:36',
name: 'Category 2'
}
])
})
}) // end formatRecords


Expand Down