Edits history of script submission #364 for ' Postgres with TLS / SSL (postgresql)'

  • deno
    import { Client } from "https://deno.land/x/[email protected]/mod.ts";
    import * as wmill from "https://deno.land/x/[email protected]/mod.ts";
    
    //PG parameterized statement. No SQL injection is possible.
    export async function main(
      dbConfig: wmill.Resource<"postgresql">,
      tlsSettings: wmill.Resource<"postgres-tls">,
      sql: string,
    ) {
      // small hack since we want to store the caCertificate as a secret in winmill.
      dbConfig.tls = tlsSettings;
      dbConfig.tls.caCertificates = [dbConfig.tls.caCertificate];
    
      const client = new Client(dbConfig);
      await client.connect();
    
      const res = await client.queryObject(
        sql,
      );
    
      await client.end();
    
      return res.rows;
    }
    

    Submitted by sindre svendby964 1119 days ago