import { Transaction } from "https://dotland.deno.dev/x/postgres@v0.19.3/query/transaction.ts";
This method allows executed queries to be retrieved as array entries. It supports a generic interface in order to type the entries retrieved by the query
import { Client } from "https://deno.land/x/postgres/mod.ts";
const client = new Client();
const transaction = client.createTransaction("transaction");
const {rows} = await transaction.queryArray(
"SELECT ID, NAME FROM CLIENTS"
); // Array<unknown[]>
You can pass type arguments to the query in order to hint TypeScript what the return value will be
import { Client } from "https://deno.land/x/postgres/mod.ts";
const client = new Client();
const transaction = client.createTransaction("transaction");
const { rows } = await transaction.queryArray<[number, string]>(
"SELECT ID, NAME FROM CLIENTS"
); // Array<[number, string]>
It also allows you to execute prepared stamements with template strings
import { Client } from "https://deno.land/x/postgres/mod.ts";
const client = new Client();
const transaction = client.createTransaction("transaction");
const id = 12;
// Array<[number, string]>
const { rows } = await transaction.queryArray<[number, string]>`SELECT ID, NAME FROM CLIENTS WHERE ID = ${id}`;
Parameters
optional
args: QueryArgumentsReturns
Promise<QueryArrayResult<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 } = await my_client.queryArray<[number, string]>({
text: "SELECT ID, NAME FROM CLIENTS",
name: "select_clients",
}); // Array<[number, string]>
Parameters
config: QueryOptions
Returns
Promise<QueryArrayResult<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<[number, string]>
const {rows} = await my_client.queryArray<[number, string]>`SELECT ID, NAME FROM CLIENTS WHERE ID = ${id}`;
Returns
Promise<QueryArrayResult<T>>