refactor: Format nodes-base package (A-F) (#3800)

* 🔨 prettier formated nodes - A

* 🔨 prettier formated nodes - B

*  prettier formated nodes - C

*  prettier formated nodes - D

*  prettier formated nodes - E-F

* 🎨 Adjust nodes-base formatting command (#3805)

* Format additional files in nodes A-F (#3811)

*  fixes

* 🎨 Add Mindee to ignored dirs

Co-authored-by: Iván Ovejero <ivov.src@gmail.com>
This commit is contained in:
Michael Kret
2022-08-01 23:47:55 +03:00
committed by GitHub
parent 2c17e6f3ca
commit 0ecbb4a19d
411 changed files with 12906 additions and 20148 deletions

View File

@@ -85,7 +85,8 @@ export class CrateDb implements INodeType {
default: '',
placeholder: 'SELECT id, name FROM product WHERE quantity > $1 AND price <= $2',
required: true,
description: 'The SQL query to execute. You can use n8n expressions or $1 and $2 in conjunction with query parameters.',
description:
'The SQL query to execute. You can use n8n expressions or $1 and $2 in conjunction with query parameters.',
},
// ----------------------------------
@@ -128,7 +129,8 @@ export class CrateDb implements INodeType {
},
default: '',
placeholder: 'id,name,description',
description: 'Comma-separated list of the properties which should used as columns for the new rows',
description:
'Comma-separated list of the properties which should used as columns for the new rows',
},
// ----------------------------------
@@ -172,7 +174,8 @@ export class CrateDb implements INodeType {
default: 'id',
required: true,
// eslint-disable-next-line n8n-nodes-base/node-param-description-miscased-id
description: 'Comma-separated list of the properties which decides which rows in the database should be updated. Normally that would be "id".',
description:
'Comma-separated list of the properties which decides which rows in the database should be updated. Normally that would be "id".',
},
{
displayName: 'Columns',
@@ -185,7 +188,8 @@ export class CrateDb implements INodeType {
},
default: '',
placeholder: 'name,description',
description: 'Comma-separated list of the properties which should used as columns for rows to update',
description:
'Comma-separated list of the properties which should used as columns for rows to update',
},
// ----------------------------------
@@ -230,7 +234,8 @@ export class CrateDb implements INodeType {
},
],
default: 'multiple',
description: 'The way queries should be sent to database. Can be used in conjunction with <b>Continue on Fail</b>. See <a href="https://docs.n8n.io/nodes/n8n-nodes-base.crateDb/">the docs</a> for more examples.',
description:
'The way queries should be sent to database. Can be used in conjunction with <b>Continue on Fail</b>. See <a href="https://docs.n8n.io/nodes/n8n-nodes-base.crateDb/">the docs</a> for more examples.',
},
{
displayName: 'Query Parameters',
@@ -238,14 +243,13 @@ export class CrateDb implements INodeType {
type: 'string',
displayOptions: {
show: {
'/operation': [
'executeQuery',
],
'/operation': ['executeQuery'],
},
},
default: '',
placeholder: 'quantity,price',
description: 'Comma-separated list of properties which should be used as query parameters',
description:
'Comma-separated list of properties which should be used as query parameters',
},
],
},
@@ -279,7 +283,13 @@ export class CrateDb implements INodeType {
// executeQuery
// ----------------------------------
const queryResult = await pgQuery(this.getNodeParameter, pgp, db, items, this.continueOnFail());
const queryResult = await pgQuery(
this.getNodeParameter,
pgp,
db,
items,
this.continueOnFail(),
);
returnItems = this.helpers.returnJsonArray(queryResult);
} else if (operation === 'insert') {
@@ -287,7 +297,13 @@ export class CrateDb implements INodeType {
// insert
// ----------------------------------
const insertData = await pgInsert(this.getNodeParameter, pgp, db, items, this.continueOnFail());
const insertData = await pgInsert(
this.getNodeParameter,
pgp,
db,
items,
this.continueOnFail(),
);
for (let i = 0; i < insertData.length; i++) {
returnItems.push({
@@ -300,24 +316,34 @@ export class CrateDb implements INodeType {
// ----------------------------------
const additionalFields = this.getNodeParameter('additionalFields', 0) as IDataObject;
const mode = additionalFields.mode ?? 'multiple' as string;
const mode = additionalFields.mode ?? ('multiple' as string);
if(mode === 'independently') {
const updateItems = await pgUpdate(this.getNodeParameter, pgp, db, items, this.continueOnFail());
if (mode === 'independently') {
const updateItems = await pgUpdate(
this.getNodeParameter,
pgp,
db,
items,
this.continueOnFail(),
);
returnItems = this.helpers.returnJsonArray(updateItems);
} else if(mode === 'multiple') {
} else if (mode === 'multiple') {
// Crate db does not support multiple-update queries
// Therefore we cannot invoke `pgUpdate` using multiple mode
// so we have to call multiple updates manually here
const table = this.getNodeParameter('table', 0) as string;
const schema = this.getNodeParameter('schema', 0) as string;
const updateKeys = (this.getNodeParameter('updateKey', 0) as string).split(',').map(column => column.trim());
const columns = (this.getNodeParameter('columns', 0) as string).split(',').map(column => column.trim());
const updateKeys = (this.getNodeParameter('updateKey', 0) as string)
.split(',')
.map((column) => column.trim());
const columns = (this.getNodeParameter('columns', 0) as string)
.split(',')
.map((column) => column.trim());
const queryColumns = columns.slice();
updateKeys.forEach(updateKey => {
updateKeys.forEach((updateKey) => {
if (!queryColumns.includes(updateKey)) {
columns.unshift(updateKey);
queryColumns.unshift('?' + updateKey);
@@ -326,24 +352,36 @@ export class CrateDb implements INodeType {
const cs = new pgp.helpers.ColumnSet(queryColumns, { table: { table, schema } });
const where = ' WHERE ' + updateKeys.map(updateKey => pgp.as.name(updateKey) + ' = ${' + updateKey + '}').join(' AND ');
const where =
' WHERE ' +
updateKeys
.map((updateKey) => pgp.as.name(updateKey) + ' = ${' + updateKey + '}')
.join(' AND ');
// updateKeyValue = item.json[updateKey] as string | number;
// if (updateKeyValue === undefined) {
// throw new NodeOperationError(this.getNode(), 'No value found for update key!');
// }
const returning = generateReturning(pgp, this.getNodeParameter('returnFields', 0) as string);
const queries:string[] = [];
const returning = generateReturning(
pgp,
this.getNodeParameter('returnFields', 0) as string,
);
const queries: string[] = [];
for (let i = 0; i < items.length; i++) {
const itemCopy = getItemCopy(items[i], columns);
queries.push(pgp.helpers.update(itemCopy, cs) + pgp.as.format(where, itemCopy) + returning);
queries.push(
pgp.helpers.update(itemCopy, cs) + pgp.as.format(where, itemCopy) + returning,
);
}
const updateItems = await db.multi(pgp.helpers.concat(queries));
returnItems = this.helpers.returnJsonArray(getItemsCopy(items, columns) as IDataObject[]);
}
} else {
await pgp.end();
throw new NodeOperationError(this.getNode(), `The operation "${operation}" is not supported!`);
throw new NodeOperationError(
this.getNode(),
`The operation "${operation}" is not supported!`,
);
}
// Close the connection