mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-26 08:01:38 +00:00
fix(deno-client): wrap the deno-postgres client and not the query statement
This commit is contained in:
+25
-8
@@ -1,14 +1,31 @@
|
||||
import { Client } from "https://deno.land/x/postgres@v0.16.1/mod.ts"
|
||||
import { type Resource, type Sql } from "./mod.ts"
|
||||
import { type Resource } from "./mod.ts"
|
||||
|
||||
export async function pgQuery(
|
||||
db: Resource<"postgresql">,
|
||||
query: Sql
|
||||
/**
|
||||
* deno-postgres client API is very flexible:
|
||||
* https://deno.land/x/postgres@v0.16.1/mod.ts?s=QueryClient
|
||||
*
|
||||
* @param db the postgresql resource to generate the client for
|
||||
*
|
||||
* @returns the client for the resource
|
||||
*
|
||||
* Usage:
|
||||
* Static query:
|
||||
* ```ts
|
||||
* const {rows} = await pgClient(db).queryObject(
|
||||
* "SELECT ID, NAME FROM CLIENTS"
|
||||
* );
|
||||
* ```
|
||||
*
|
||||
* Prepared Statements:
|
||||
* ```ts
|
||||
* const { rows } = await pgClient(db).queryObject`SELECT ID, NAME FROM CLIENTS WHERE ID = ${id}`;
|
||||
* ```
|
||||
*/
|
||||
export function pgClient(
|
||||
db: Resource<"postgresql">
|
||||
) {
|
||||
db.database = db.dbname
|
||||
db.hostname = db.host
|
||||
|
||||
const returned_query = await new Client(db).queryObject(query)
|
||||
|
||||
return returned_query.rows
|
||||
return new Client(db)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user