0
Postgres with TLS / SSL
One script reply has been approved by the moderators Verified

example on how to run a sql against a database that needs a ca certificate

Created by sindre svendby964 587 days ago Viewed 9895 times
0
Submitted by sindre svendby964 Deno
Verified 587 days ago
1
import { Client } from "https://deno.land/x/postgres@v0.17.0/mod.ts";
2

3
type Postgresql = {
4
  host: string;
5
  port: number;
6
  user: string;
7
  dbname: string;
8
  sslmode: string;
9
  password: string;
10
};
11

12
type Cacertificate = {
13
  certificate: string;
14
};
15
export async function main(
16
  dbConfig: Postgresql,
17
  cacertificate: Cacertificate,
18
  sql: string = "SELECT 1 as id",
19
) {
20
  dbConfig.tls = {
21
    enabled: true,
22
    enforce: true,
23
    caCertificates: [cacertificate.certificate],
24
  };
25
  const client = new Client(dbConfig);
26
  await client.connect();
27

28
  const res = await client.queryObject(sql);
29

30
  await client.end();
31

32
  return res.rows;
33
}
34

Other submissions