mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-19 11:01:15 +00:00
feat(Postgres Node): Overhaul node
This commit is contained in:
47
packages/nodes-base/nodes/Postgres/v2/methods/listSearch.ts
Normal file
47
packages/nodes-base/nodes/Postgres/v2/methods/listSearch.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import type { ILoadOptionsFunctions, INodeListSearchResult } from 'n8n-workflow';
|
||||
import type { ConnectionsData } from '../helpers/interfaces';
|
||||
import { Connections } from '../transport';
|
||||
|
||||
export async function schemaSearch(this: ILoadOptionsFunctions): Promise<INodeListSearchResult> {
|
||||
const credentials = await this.getCredentials('postgres');
|
||||
|
||||
const { db } = (await Connections.getInstance(credentials)) as ConnectionsData;
|
||||
|
||||
try {
|
||||
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,
|
||||
})),
|
||||
};
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
export async function tableSearch(this: ILoadOptionsFunctions): Promise<INodeListSearchResult> {
|
||||
const credentials = await this.getCredentials('postgres');
|
||||
|
||||
const { db } = (await Connections.getInstance(credentials)) as ConnectionsData;
|
||||
|
||||
const schema = this.getNodeParameter('schema', 0, {
|
||||
extractValue: true,
|
||||
}) as string;
|
||||
|
||||
try {
|
||||
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,
|
||||
})),
|
||||
};
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user