Files
n8n-enterprise-unlocked/packages/nodes-base/nodes/Postgres/v2/methods/listSearch.ts
OlegIvaniv 0eb4d9fc16 fix(Postgres Node): Always return TIMESTAMP and TIMESTAMPZ as ISO string (#6145)
* fix(Postgres Node): Always return TIMESTAMP and TIMESTAMPZ as ISO string

* Fix linting issues
2023-05-04 17:25:54 +02:00

50 lines
1.5 KiB
TypeScript

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 options = { nodeVersion: this.getNode().typeVersion };
const { db } = (await Connections.getInstance(credentials, options)) 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 options = { nodeVersion: this.getNode().typeVersion };
const { db } = (await Connections.getInstance(credentials, options)) 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;
}
}