Skip to content

Commit

Permalink
fix(Postgres Node): Always return TIMESTAMP and TIMESTAMPZ as ISO str…
Browse files Browse the repository at this point in the history
…ings
  • Loading branch information
OlegIvaniv committed May 1, 2023
1 parent 4cbb05b commit c64ff9e
Show file tree
Hide file tree
Showing 23 changed files with 2,348 additions and 30 deletions.
4 changes: 3 additions & 1 deletion packages/nodes-base/nodes/Postgres/Postgres.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { VersionedNodeType } from 'n8n-workflow';

import { PostgresV1 } from './v1/PostgresV1.node';
import { PostgresV2 } from './v2/PostgresV2.node';
import { PostgresV3 } from './v3/PostgresV3.node';

export class Postgres extends VersionedNodeType {
constructor() {
Expand All @@ -11,13 +12,14 @@ export class Postgres extends VersionedNodeType {
name: 'postgres',
icon: 'file:postgres.svg',
group: ['input'],
defaultVersion: 2,
defaultVersion: 3,
description: 'Get, add and update data in Postgres',
};

const nodeVersions: IVersionedNodeType['nodeVersions'] = {
1: new PostgresV1(baseDescription),
2: new PostgresV2(baseDescription),
3: new PostgresV3(baseDescription),
};

super(nodeVersions, baseDescription);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import type { IDataObject, IExecuteFunctions, IGetNodeParameterOptions, INode } from 'n8n-workflow';

import type { ColumnInfo, PgpDatabase, QueriesRunner } from '../../v2/helpers/interfaces';
import type { ColumnInfo, PgpDatabase, QueriesRunner } from '../../v3/helpers/interfaces';

import { get } from 'lodash';

import * as deleteTable from '../../v2/actions/database/deleteTable.operation';
import * as executeQuery from '../../v2/actions/database/executeQuery.operation';
import * as insert from '../../v2/actions/database/insert.operation';
import * as select from '../../v2/actions/database/select.operation';
import * as update from '../../v2/actions/database/update.operation';
import * as upsert from '../../v2/actions/database/upsert.operation';
import * as deleteTable from '../../v3/actions/database/deleteTable.operation';
import * as executeQuery from '../../v3/actions/database/executeQuery.operation';
import * as insert from '../../v3/actions/database/insert.operation';
import * as select from '../../v3/actions/database/select.operation';
import * as update from '../../v3/actions/database/update.operation';
import * as upsert from '../../v3/actions/database/upsert.operation';

const runQueries: QueriesRunner = jest.fn();

const node: INode = {
id: '1',
name: 'Postgres node',
typeVersion: 2,
typeVersion: 3,
type: 'n8n-nodes-base.postgres',
position: [60, 760],
parameters: {
Expand Down Expand Up @@ -53,7 +53,7 @@ const createMockDb = (columnInfo: ColumnInfo[]) => {
};

// if node parameters copied from canvas all default parameters has to be added manually as JSON would not have them
describe('Test PostgresV2, deleteTable operation', () => {
describe('Test PostgresV3, deleteTable operation', () => {
afterEach(() => {
jest.clearAllMocks();
});
Expand Down Expand Up @@ -185,7 +185,7 @@ describe('Test PostgresV2, deleteTable operation', () => {
});
});

describe('Test PostgresV2, executeQuery operation', () => {
describe('Test PostgresV3, executeQuery operation', () => {
afterEach(() => {
jest.clearAllMocks();
});
Expand Down Expand Up @@ -215,7 +215,7 @@ describe('Test PostgresV2, executeQuery operation', () => {
});
});

describe('Test PostgresV2, insert operation', () => {
describe('Test PostgresV3, insert operation', () => {
afterEach(() => {
jest.clearAllMocks();
});
Expand Down Expand Up @@ -361,7 +361,7 @@ describe('Test PostgresV2, insert operation', () => {
});
});

describe('Test PostgresV2, select operation', () => {
describe('Test PostgresV3, select operation', () => {
afterEach(() => {
jest.clearAllMocks();
});
Expand Down Expand Up @@ -467,7 +467,7 @@ describe('Test PostgresV2, select operation', () => {
});
});

describe('Test PostgresV2, update operation', () => {
describe('Test PostgresV3, update operation', () => {
afterEach(() => {
jest.clearAllMocks();
});
Expand Down Expand Up @@ -630,7 +630,7 @@ describe('Test PostgresV2, update operation', () => {
});
});

describe('Test PostgresV2, upsert operation', () => {
describe('Test PostgresV3, upsert operation', () => {
it('dataMode: define, should call runQueries with', async () => {
const nodeParameters: IDataObject = {
operation: 'upsert',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { constructExecutionMetaData } from 'n8n-core';
import type { IDataObject, INode } from 'n8n-workflow';

import type { PgpDatabase } from '../../v2/helpers/interfaces';
import { configureQueryRunner } from '../../v2/helpers/utils';
import type { PgpDatabase } from '../../v3/helpers/interfaces';
import { configureQueryRunner } from '../../v3/helpers/utils';

import pgPromise from 'pg-promise';

const node: INode = {
id: '1',
name: 'Postgres node',
typeVersion: 2,
typeVersion: 3,
type: 'n8n-nodes-base.postgres',
position: [60, 760],
parameters: {
Expand All @@ -34,7 +34,7 @@ const createMockDb = (returnData: IDataObject | IDataObject[]) => {
} as unknown as PgpDatabase;
};

describe('Test PostgresV2, runQueries', () => {
describe('Test PostgresV3, runQueries', () => {
it('should execute, should return success true', async () => {
const pgp = pgPromise();
const db = createMockDb([]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ import {
prepareItem,
replaceEmptyStringsByNulls,
wrapData,
} from '../../v2/helpers/utils';
} from '../../v3/helpers/utils';

const node: INode = {
id: '1',
name: 'Postgres node',
typeVersion: 2,
typeVersion: 3,
type: 'n8n-nodes-base.postgres',
position: [60, 760],
parameters: {
operation: 'executeQuery',
},
};

describe('Test PostgresV2, wrapData', () => {
describe('Test PostgresV3, wrapData', () => {
it('should wrap object in json', () => {
const data = {
id: 1,
Expand Down Expand Up @@ -62,7 +62,7 @@ describe('Test PostgresV2, wrapData', () => {
});
});

describe('Test PostgresV2, prepareErrorItem', () => {
describe('Test PostgresV3, prepareErrorItem', () => {
it('should return error info item', () => {
const items = [
{
Expand All @@ -89,7 +89,7 @@ describe('Test PostgresV2, prepareErrorItem', () => {
});
});

describe('Test PostgresV2, parsePostgresError', () => {
describe('Test PostgresV3, parsePostgresError', () => {
it('should return NodeOperationError', () => {
const error = new Error('Test error');

Expand Down Expand Up @@ -123,7 +123,7 @@ describe('Test PostgresV2, parsePostgresError', () => {
});
});

describe('Test PostgresV2, addWhereClauses', () => {
describe('Test PostgresV3, addWhereClauses', () => {
it('should add where clauses to query', () => {
const query = 'SELECT * FROM $1:name.$2:name';
const values = ['public', 'my_table'];
Expand Down Expand Up @@ -189,7 +189,7 @@ describe('Test PostgresV2, addWhereClauses', () => {
});
});

describe('Test PostgresV2, addSortRules', () => {
describe('Test PostgresV3, addSortRules', () => {
it('should ORDER BY ASC', () => {
const query = 'SELECT * FROM $1:name.$2:name';
const values = ['public', 'my_table'];
Expand Down Expand Up @@ -237,7 +237,7 @@ describe('Test PostgresV2, addSortRules', () => {
});
});

describe('Test PostgresV2, addReturning', () => {
describe('Test PostgresV3, addReturning', () => {
it('should add RETURNING', () => {
const query = 'UPDATE $1:name.$2:name SET $5:name = $6 WHERE $3:name = $4';
const values = ['public', 'my_table', 'id', '1', 'foo', 'updated'];
Expand Down Expand Up @@ -272,7 +272,7 @@ describe('Test PostgresV2, addReturning', () => {
});
});

describe('Test PostgresV2, replaceEmptyStringsByNulls', () => {
describe('Test PostgresV3, replaceEmptyStringsByNulls', () => {
it('should replace empty string by null', () => {
const items = [
{ json: { foo: 'bar', bar: '', spam: undefined } },
Expand Down Expand Up @@ -303,7 +303,7 @@ describe('Test PostgresV2, replaceEmptyStringsByNulls', () => {
});
});

describe('Test PostgresV2, prepareItem', () => {
describe('Test PostgresV3, prepareItem', () => {
it('should convert fixedColections values to object', () => {
const values = [
{
Expand Down Expand Up @@ -331,7 +331,7 @@ describe('Test PostgresV2, prepareItem', () => {
});
});

describe('Test PostgresV2, checkItemAgainstSchema', () => {
describe('Test PostgresV3, checkItemAgainstSchema', () => {
it('should not throw error', () => {
const item = { foo: 'updated', id: 2 };
const columnsInfo = [
Expand Down
29 changes: 29 additions & 0 deletions packages/nodes-base/nodes/Postgres/v3/PostgresV3.node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* eslint-disable n8n-nodes-base/node-filename-against-convention */
import type { IExecuteFunctions } from 'n8n-core';
import type {
INodeExecutionData,
INodeType,
INodeTypeBaseDescription,
INodeTypeDescription,
} from 'n8n-workflow';
import { router } from './actions/router';

import { versionDescription } from './actions/versionDescription';
import { credentialTest, listSearch, loadOptions } from './methods';

export class PostgresV3 implements INodeType {
description: INodeTypeDescription;

constructor(baseDescription: INodeTypeBaseDescription) {
this.description = {
...baseDescription,
...versionDescription,
};
}

methods = { credentialTest, listSearch, loadOptions };

async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
return router.call(this);
}
}
Loading

0 comments on commit c64ff9e

Please sign in to comment.