How to render a table with data from 2 databases #3100
-
As the title suggests I'd like to show data from 2 Postgres databases in a single application's "table" component. The docs suggest this is possible but I'd couldn't find a detailed guide on how to approach this. I suspect I cannot use a single Postgres Query but must instead use a JS/Python script that connects to both databases, runs the 2 queries and builds the result JSON. I tried this from Windmill Hub but the query fails.
I have tested the DB connection with a simple query on a table component and had no issues so the connection issue is due to this script. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@uvinw if you need to use a import { Client } from "https://deno.land/x/[email protected]/mod.ts";
import * as wmill from "npm:windmill-client@1";
export async function main(sql:string) {
return await pgQuery(sql);
}
export async function pgQuery(sql: string) {
const dbConfig = await wmill.getResource("<RESOURCE_FOLDER>");
const clientOptions = {
hostname: dbConfig.host,
port: dbConfig.port,
user: dbConfig.user,
database: dbConfig.dbname,
password: dbConfig.password,
host_type: "tcp",
tls: {
enabled: true,
enforce: true,
caCertificates: [dbConfig.root_certificate_pem],
},
};
const client = new Client(clientOptions);
await client.connect();
const res = await client.queryObject(sql);
await client.end();
return res.rows;
} |
Beta Was this translation helpful? Give feedback.
@uvinw if you need to use a
ca-cert
the below script works with the postgres resource.