mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-19 00:20:48 -08:00
fix(Postgres Node): Allow users to wrap strings with $$ (#12034)
This commit is contained in:
parent
a5e01cfa23
commit
0c15e30778
|
@ -217,7 +217,7 @@ describe('Test PostgresV2, executeQuery operation', () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(runQueries).toHaveBeenCalledWith(
|
expect(runQueries).toHaveBeenCalledWith(
|
||||||
[{ query: 'select * from $1:name;', values: ['my_table'] }],
|
[{ query: 'select * from $1:name;', values: ['my_table'], options: { partial: true } }],
|
||||||
items,
|
items,
|
||||||
nodeOptions,
|
nodeOptions,
|
||||||
);
|
);
|
||||||
|
@ -239,7 +239,7 @@ describe('Test PostgresV2, executeQuery operation', () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(runQueries).toHaveBeenCalledWith(
|
expect(runQueries).toHaveBeenCalledWith(
|
||||||
[{ query: 'select $1;', values: ['$1'] }],
|
[{ query: 'select $1;', values: ['$1'], options: { partial: true } }],
|
||||||
items,
|
items,
|
||||||
nodeOptions,
|
nodeOptions,
|
||||||
);
|
);
|
||||||
|
@ -263,7 +263,7 @@ describe('Test PostgresV2, executeQuery operation', () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(runQueries).toHaveBeenCalledWith(
|
expect(runQueries).toHaveBeenCalledWith(
|
||||||
[{ query: "select '$1';", values: ['my_table'] }],
|
[{ query: "select '$1';", values: ['my_table'], options: { partial: true } }],
|
||||||
items,
|
items,
|
||||||
nodeOptions,
|
nodeOptions,
|
||||||
);
|
);
|
||||||
|
@ -288,7 +288,7 @@ describe('Test PostgresV2, executeQuery operation', () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(runQueries).toHaveBeenCalledWith(
|
expect(runQueries).toHaveBeenCalledWith(
|
||||||
[{ query: 'select $2;', values: ['my_table', '$1'] }],
|
[{ query: 'select $2;', values: ['my_table', '$1'], options: { partial: true } }],
|
||||||
items,
|
items,
|
||||||
nodeOptions,
|
nodeOptions,
|
||||||
);
|
);
|
||||||
|
@ -313,6 +313,54 @@ describe('Test PostgresV2, executeQuery operation', () => {
|
||||||
);
|
);
|
||||||
}).not.toThrow();
|
}).not.toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should allow users to use $$ instead of strings', async () => {
|
||||||
|
const nodeParameters: IDataObject = {
|
||||||
|
operation: 'executeQuery',
|
||||||
|
query: 'INSERT INTO dollar_bug (description) VALUES ($$34test$$);',
|
||||||
|
options: {},
|
||||||
|
};
|
||||||
|
const nodeOptions = nodeParameters.options as IDataObject;
|
||||||
|
|
||||||
|
expect(async () => {
|
||||||
|
await executeQuery.execute.call(
|
||||||
|
createMockExecuteFunction(nodeParameters),
|
||||||
|
runQueries,
|
||||||
|
items,
|
||||||
|
nodeOptions,
|
||||||
|
);
|
||||||
|
}).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should allow users to use $$ instead of strings while using query parameters', async () => {
|
||||||
|
const nodeParameters: IDataObject = {
|
||||||
|
operation: 'executeQuery',
|
||||||
|
query: 'INSERT INTO dollar_bug (description) VALUES ($1 || $$4more text$$)',
|
||||||
|
options: {
|
||||||
|
queryReplacement: '={{ $3This is a test }}',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const nodeOptions = nodeParameters.options as IDataObject;
|
||||||
|
|
||||||
|
await executeQuery.execute.call(
|
||||||
|
createMockExecuteFunction(nodeParameters),
|
||||||
|
runQueries,
|
||||||
|
items,
|
||||||
|
nodeOptions,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(runQueries).toHaveBeenCalledWith(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
query: 'INSERT INTO dollar_bug (description) VALUES ($1 || $$4more text$$)',
|
||||||
|
values: [' $3This is a test '],
|
||||||
|
options: { partial: true },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
items,
|
||||||
|
nodeOptions,
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Test PostgresV2, insert operation', () => {
|
describe('Test PostgresV2, insert operation', () => {
|
||||||
|
|
|
@ -143,7 +143,7 @@ export async function execute(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
queries.push({ query, values });
|
queries.push({ query, values, options: { partial: true } });
|
||||||
}
|
}
|
||||||
|
|
||||||
return await runQueries(queries, items, nodeOptions);
|
return await runQueries(queries, items, nodeOptions);
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
import type { IDataObject, INodeExecutionData, SSHCredentials } from 'n8n-workflow';
|
import type { IDataObject, INodeExecutionData, SSHCredentials } from 'n8n-workflow';
|
||||||
import type pgPromise from 'pg-promise';
|
import type pgPromise from 'pg-promise';
|
||||||
|
import { type IFormattingOptions } from 'pg-promise';
|
||||||
import type pg from 'pg-promise/typescript/pg-subset';
|
import type pg from 'pg-promise/typescript/pg-subset';
|
||||||
|
|
||||||
export type QueryMode = 'single' | 'transaction' | 'independently';
|
export type QueryMode = 'single' | 'transaction' | 'independently';
|
||||||
|
|
||||||
export type QueryValue = string | number | IDataObject | string[];
|
export type QueryValue = string | number | IDataObject | string[];
|
||||||
export type QueryValues = QueryValue[];
|
export type QueryValues = QueryValue[];
|
||||||
export type QueryWithValues = { query: string; values?: QueryValues };
|
export type QueryWithValues = { query: string; values?: QueryValues; options?: IFormattingOptions };
|
||||||
|
|
||||||
export type WhereClause = { column: string; condition: string; value: string | number };
|
export type WhereClause = { column: string; condition: string; value: string | number };
|
||||||
export type SortRule = { column: string; direction: string };
|
export type SortRule = { column: string; direction: string };
|
||||||
|
|
Loading…
Reference in a new issue