add pgQuery to deno-client

This commit is contained in:
Ruben Fiszel
2022-08-17 11:53:22 +02:00
parent 40abf870c5
commit a64fa1054b
2 changed files with 15 additions and 0 deletions
+1
View File
@@ -132,3 +132,4 @@ export async function databaseUrlFromResource(path: string): Promise<string> {
const resource = await getResource(path)
return `postgresql://${resource.user}:${resource.password}@${resource.host}:${resource.port}/${resource.dbname}?sslmode=${resource.sslmode}`
}
+14
View File
@@ -0,0 +1,14 @@
import { Client } from "https://deno.land/x/postgres@v0.16.1/mod.ts"
import { type Resource, type Sql } from "./mod.ts"
export async function pgQuery(
db: Resource<"postgresql">,
query: Sql
) {
db.database = db.dbname
db.hostname = db.host
const returned_query = await new Client(db).queryObject(query)
return returned_query.rows
}