mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 12:57:29 -08:00
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:
parent
d381578926
commit
0eb4d9fc16
|
@ -11,13 +11,14 @@ export class Postgres extends VersionedNodeType {
|
|||
name: 'postgres',
|
||||
icon: 'file:postgres.svg',
|
||||
group: ['input'],
|
||||
defaultVersion: 2,
|
||||
defaultVersion: 2.1,
|
||||
description: 'Get, add and update data in Postgres',
|
||||
};
|
||||
|
||||
const nodeVersions: IVersionedNodeType['nodeVersions'] = {
|
||||
1: new PostgresV1(baseDescription),
|
||||
2: new PostgresV2(baseDescription),
|
||||
2.1: new PostgresV2(baseDescription),
|
||||
};
|
||||
|
||||
super(nodeVersions, baseDescription);
|
||||
|
|
|
@ -17,6 +17,7 @@ export async function router(this: IExecuteFunctions): Promise<INodeExecutionDat
|
|||
|
||||
const credentials = await this.getCredentials('postgres');
|
||||
const options = this.getNodeParameter('options', 0, {});
|
||||
options.nodeVersion = this.getNode().typeVersion;
|
||||
|
||||
const { db, pgp, sshClient } = (await Connections.getInstance(
|
||||
credentials,
|
||||
|
|
|
@ -8,7 +8,7 @@ export const versionDescription: INodeTypeDescription = {
|
|||
name: 'postgres',
|
||||
icon: 'file:postgres.svg',
|
||||
group: ['input'],
|
||||
version: 2,
|
||||
version: [2, 2.1],
|
||||
subtitle: '={{ $parameter["operation"] }}',
|
||||
description: 'Get, add and update data in Postgres',
|
||||
defaults: {
|
||||
|
|
|
@ -4,8 +4,9 @@ import { Connections } from '../transport';
|
|||
|
||||
export async function schemaSearch(this: ILoadOptionsFunctions): Promise<INodeListSearchResult> {
|
||||
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 {
|
||||
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> {
|
||||
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, {
|
||||
extractValue: true,
|
||||
|
|
|
@ -5,8 +5,9 @@ import { Connections } from '../transport';
|
|||
|
||||
export async function getColumns(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
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, {
|
||||
extractValue: true,
|
||||
|
|
|
@ -47,6 +47,15 @@ async function configurePostgres(
|
|||
) {
|
||||
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') {
|
||||
pgp.pg.types.setTypeParser(20, (value: string) => {
|
||||
return parseInt(value, 10);
|
||||
|
|
Loading…
Reference in a new issue