fix(deno-client): pg module now supports prepared statements

This commit is contained in:
Ruben Fiszel
2022-08-20 12:02:56 +02:00
parent 32d067f8c0
commit 5900a03c04
2 changed files with 25 additions and 1 deletions
+1 -1
View File
@@ -7,9 +7,9 @@ export {
UserApi, WorkspaceApi
} from './windmill-api/index.ts'
export type Sql = string
export type Email = string
export type Base64 = string
export type Sql = string
export type Resource<S extends string> = any
/**
+24
View File
@@ -29,3 +29,27 @@ export function pgClient(
db.hostname = db.host
return new Client(db)
}
/**
* 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 rows corresponding to the returned objetcs
*
* Prepared Statements:
* ```ts
* const { rows } = await pgSql(db)`SELECT ID, NAME FROM CLIENTS WHERE ID = ${id}`;
* ```
*/
export function pgSql(
db: Resource<"postgresql">
) {
return async function queryObject(
query: TemplateStringsArray,
...args: unknown[]
) {
return await pgClient(db).queryObject(query, args)
}
}