diff --git a/deno-client/pg.ts b/deno-client/pg.ts index b33d956e22..5f79c056eb 100644 --- a/deno-client/pg.ts +++ b/deno-client/pg.ts @@ -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) }