diff --git a/packages/nodes-base/nodes/Postgres/PostgresTrigger.functions.ts b/packages/nodes-base/nodes/Postgres/PostgresTrigger.functions.ts index f46eba14813b5..6dcb91ce7d7c3 100644 --- a/packages/nodes-base/nodes/Postgres/PostgresTrigger.functions.ts +++ b/packages/nodes-base/nodes/Postgres/PostgresTrigger.functions.ts @@ -102,7 +102,6 @@ export async function searchSchema(this: ILoadOptionsFunctions): Promise 1 && !node.executeOnce) { diff --git a/packages/nodes-base/nodes/Postgres/v2/methods/listSearch.ts b/packages/nodes-base/nodes/Postgres/v2/methods/listSearch.ts index c20319d5ac769..67482d4381474 100644 --- a/packages/nodes-base/nodes/Postgres/v2/methods/listSearch.ts +++ b/packages/nodes-base/nodes/Postgres/v2/methods/listSearch.ts @@ -9,18 +9,14 @@ export async function schemaSearch(this: ILoadOptionsFunctions): Promise ({ - name: schema.schema_name as string, - value: schema.schema_name as string, - })), - }; - } finally { - if (!db.$pool.ending) await db.$pool.end(); - } + const response = await db.any('SELECT schema_name FROM information_schema.schemata'); + + return { + results: response.map((schema) => ({ + name: schema.schema_name as string, + value: schema.schema_name as string, + })), + }; } export async function tableSearch(this: ILoadOptionsFunctions): Promise { const credentials = await this.getCredentials('postgres'); @@ -32,19 +28,15 @@ export async function tableSearch(this: ILoadOptionsFunctions): Promise ({ - name: table.table_name as string, - value: table.table_name as string, - })), - }; - } finally { - if (!db.$pool.ending) await db.$pool.end(); - } + const response = await db.any( + 'SELECT table_name FROM information_schema.tables WHERE table_schema=$1', + [schema], + ); + + return { + results: response.map((table) => ({ + name: table.table_name as string, + value: table.table_name as string, + })), + }; } diff --git a/packages/nodes-base/nodes/Postgres/v2/methods/loadOptions.ts b/packages/nodes-base/nodes/Postgres/v2/methods/loadOptions.ts index d906c7e0bd099..c8fb75436dd88 100644 --- a/packages/nodes-base/nodes/Postgres/v2/methods/loadOptions.ts +++ b/packages/nodes-base/nodes/Postgres/v2/methods/loadOptions.ts @@ -18,17 +18,13 @@ export async function getColumns(this: ILoadOptionsFunctions): Promise ({ - name: column.column_name, - value: column.column_name, - description: `Type: ${column.data_type.toUpperCase()}, Nullable: ${column.is_nullable}`, - })); - } finally { - if (!db.$pool.ending) await db.$pool.end(); - } + const columns = await getTableSchema(db, schema, table); + + return columns.map((column) => ({ + name: column.column_name, + value: column.column_name, + description: `Type: ${column.data_type.toUpperCase()}, Nullable: ${column.is_nullable}`, + })); } export async function getColumnsMultiOptions( diff --git a/packages/nodes-base/nodes/Postgres/v2/methods/resourceMapping.ts b/packages/nodes-base/nodes/Postgres/v2/methods/resourceMapping.ts index 99f40cb1da54c..acc44b53149d7 100644 --- a/packages/nodes-base/nodes/Postgres/v2/methods/resourceMapping.ts +++ b/packages/nodes-base/nodes/Postgres/v2/methods/resourceMapping.ts @@ -63,34 +63,30 @@ export async function getMappingColumns( extractValue: true, }) as string; - try { - const columns = await getTableSchema(db, schema, table, { getColumnsForResourceMapper: true }); - const unique = operation === 'upsert' ? await uniqueColumns(db, table, schema) : []; - const enumInfo = await getEnums(db); - const fields = await Promise.all( - columns.map(async (col) => { - const canBeUsedToMatch = - operation === 'upsert' ? unique.some((u) => u.attname === col.column_name) : true; - const type = mapPostgresType(col.data_type); - const options = - type === 'options' ? getEnumValues(enumInfo, col.udt_name as string) : undefined; - const hasDefault = Boolean(col.column_default); - const isGenerated = col.is_generated === 'ALWAYS' || col.identity_generation === 'ALWAYS'; - const nullable = col.is_nullable === 'YES'; - return { - id: col.column_name, - displayName: col.column_name, - required: !nullable && !hasDefault && !isGenerated, - defaultMatch: (col.column_name === 'id' && canBeUsedToMatch) || false, - display: true, - type, - canBeUsedToMatch, - options, - }; - }), - ); - return { fields }; - } finally { - if (!db.$pool.ending) await db.$pool.end(); - } + const columns = await getTableSchema(db, schema, table, { getColumnsForResourceMapper: true }); + const unique = operation === 'upsert' ? await uniqueColumns(db, table, schema) : []; + const enumInfo = await getEnums(db); + const fields = await Promise.all( + columns.map(async (col) => { + const canBeUsedToMatch = + operation === 'upsert' ? unique.some((u) => u.attname === col.column_name) : true; + const type = mapPostgresType(col.data_type); + const options = + type === 'options' ? getEnumValues(enumInfo, col.udt_name as string) : undefined; + const hasDefault = Boolean(col.column_default); + const isGenerated = col.is_generated === 'ALWAYS' || col.identity_generation === 'ALWAYS'; + const nullable = col.is_nullable === 'YES'; + return { + id: col.column_name, + displayName: col.column_name, + required: !nullable && !hasDefault && !isGenerated, + defaultMatch: (col.column_name === 'id' && canBeUsedToMatch) || false, + display: true, + type, + canBeUsedToMatch, + options, + }; + }), + ); + return { fields }; }