mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-20 08:01:35 +00:00
fix(deno-client): pg module now supports prepared statements
This commit is contained in:
+1
-1
@@ -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
|
||||
|
||||
/**
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user