import { Transaction } from "https://deno.land/x/postgres@v0.19.2/query/transaction.ts";
Executed queries and retrieve the data as object entries. It supports a generic in order to type the entries retrieved by the query
import { Client } from "https://deno.land/x/postgres/mod.ts";
const my_client = new Client();
const { rows: rows1 } = await my_client.queryObject(
"SELECT ID, NAME FROM CLIENTS"
); // Record<string, unknown>
const { rows: rows2 } = await my_client.queryObject<{id: number, name: string}>(
"SELECT ID, NAME FROM CLIENTS"
); // Array<{id: number, name: string}>
Parameters
optional
args: QueryArgumentsReturns
Promise<QueryObjectResult<T>>
Use the configuration object for more advance options to execute the query
import { Client } from "https://deno.land/x/postgres/mod.ts";
const my_client = new Client();
const { rows: rows1 } = await my_client.queryObject(
"SELECT ID, NAME FROM CLIENTS"
);
console.log(rows1); // [{id: 78, name: "Frank"}, {id: 15, name: "Sarah"}]
const { rows: rows2 } = await my_client.queryObject({
text: "SELECT ID, NAME FROM CLIENTS",
fields: ["personal_id", "complete_name"],
});
console.log(rows2); // [{personal_id: 78, complete_name: "Frank"}, {personal_id: 15, complete_name: "Sarah"}]
Parameters
config: QueryObjectOptions
Returns
Promise<QueryObjectResult<T>>
Execute prepared statements with template strings
import { Client } from "https://deno.land/x/postgres/mod.ts";
const my_client = new Client();
const id = 12;
// Array<{id: number, name: string}>
const { rows } = await my_client.queryObject<{id: number, name: string}>`SELECT ID, NAME FROM CLIENTS WHERE ID = ${id}`;
Returns
Promise<QueryObjectResult<T>>