fix(Postgres Node): Always return TIMESTAMP and TIMESTAMPZ as ISO string (#6145)

* fix(Postgres Node): Always return TIMESTAMP and TIMESTAMPZ as ISO string

* Fix linting issues
This commit is contained in:
OlegIvaniv 2023-05-04 17:25:54 +02:00 committed by GitHub
parent d381578926
commit 0eb4d9fc16
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 5 deletions

View file

@ -11,13 +11,14 @@ export class Postgres extends VersionedNodeType {
name: 'postgres', name: 'postgres',
icon: 'file:postgres.svg', icon: 'file:postgres.svg',
group: ['input'], group: ['input'],
defaultVersion: 2, defaultVersion: 2.1,
description: 'Get, add and update data in Postgres', description: 'Get, add and update data in Postgres',
}; };
const nodeVersions: IVersionedNodeType['nodeVersions'] = { const nodeVersions: IVersionedNodeType['nodeVersions'] = {
1: new PostgresV1(baseDescription), 1: new PostgresV1(baseDescription),
2: new PostgresV2(baseDescription), 2: new PostgresV2(baseDescription),
2.1: new PostgresV2(baseDescription),
}; };
super(nodeVersions, baseDescription); super(nodeVersions, baseDescription);

View file

@ -17,6 +17,7 @@ export async function router(this: IExecuteFunctions): Promise<INodeExecutionDat
const credentials = await this.getCredentials('postgres'); const credentials = await this.getCredentials('postgres');
const options = this.getNodeParameter('options', 0, {}); const options = this.getNodeParameter('options', 0, {});
options.nodeVersion = this.getNode().typeVersion;
const { db, pgp, sshClient } = (await Connections.getInstance( const { db, pgp, sshClient } = (await Connections.getInstance(
credentials, credentials,

View file

@ -8,7 +8,7 @@ export const versionDescription: INodeTypeDescription = {
name: 'postgres', name: 'postgres',
icon: 'file:postgres.svg', icon: 'file:postgres.svg',
group: ['input'], group: ['input'],
version: 2, version: [2, 2.1],
subtitle: '={{ $parameter["operation"] }}', subtitle: '={{ $parameter["operation"] }}',
description: 'Get, add and update data in Postgres', description: 'Get, add and update data in Postgres',
defaults: { defaults: {

View file

@ -4,8 +4,9 @@ import { Connections } from '../transport';
export async function schemaSearch(this: ILoadOptionsFunctions): Promise<INodeListSearchResult> { export async function schemaSearch(this: ILoadOptionsFunctions): Promise<INodeListSearchResult> {
const credentials = await this.getCredentials('postgres'); const credentials = await this.getCredentials('postgres');
const options = { nodeVersion: this.getNode().typeVersion };
const { db } = (await Connections.getInstance(credentials)) as ConnectionsData; const { db } = (await Connections.getInstance(credentials, options)) as ConnectionsData;
try { try {
const response = await db.any('SELECT schema_name FROM information_schema.schemata'); const response = await db.any('SELECT schema_name FROM information_schema.schemata');
@ -22,8 +23,9 @@ export async function schemaSearch(this: ILoadOptionsFunctions): Promise<INodeLi
} }
export async function tableSearch(this: ILoadOptionsFunctions): Promise<INodeListSearchResult> { export async function tableSearch(this: ILoadOptionsFunctions): Promise<INodeListSearchResult> {
const credentials = await this.getCredentials('postgres'); const credentials = await this.getCredentials('postgres');
const options = { nodeVersion: this.getNode().typeVersion };
const { db } = (await Connections.getInstance(credentials)) as ConnectionsData; const { db } = (await Connections.getInstance(credentials, options)) as ConnectionsData;
const schema = this.getNodeParameter('schema', 0, { const schema = this.getNodeParameter('schema', 0, {
extractValue: true, extractValue: true,

View file

@ -5,8 +5,9 @@ import { Connections } from '../transport';
export async function getColumns(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> { export async function getColumns(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const credentials = await this.getCredentials('postgres'); const credentials = await this.getCredentials('postgres');
const options = { nodeVersion: this.getNode().typeVersion };
const { db } = (await Connections.getInstance(credentials)) as ConnectionsData; const { db } = (await Connections.getInstance(credentials, options)) as ConnectionsData;
const schema = this.getNodeParameter('schema', 0, { const schema = this.getNodeParameter('schema', 0, {
extractValue: true, extractValue: true,

View file

@ -47,6 +47,15 @@ async function configurePostgres(
) { ) {
const pgp = pgPromise(); const pgp = pgPromise();
if (typeof options.nodeVersion == 'number' && options.nodeVersion >= 2.1) {
// Always return dates as ISO strings
[pgp.pg.types.builtins.TIMESTAMP, pgp.pg.types.builtins.TIMESTAMPTZ].forEach((type) => {
pgp.pg.types.setTypeParser(type, (value: string) => {
return new Date(value).toISOString();
});
});
}
if (options.largeNumbersOutput === 'numbers') { if (options.largeNumbersOutput === 'numbers') {
pgp.pg.types.setTypeParser(20, (value: string) => { pgp.pg.types.setTypeParser(20, (value: string) => {
return parseInt(value, 10); return parseInt(value, 10);