Skip to main content
Module

x/postgres/mod.ts>QueryClient#queryArray

PostgreSQL driver for Deno
Extremely Popular
Latest
method QueryClient.prototype.queryArray
import { QueryClient } from "https://deno.land/x/postgres@v0.19.3/mod.ts";

Execute queries and retrieve the data as array 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.queryArray(
  "SELECT ID, NAME FROM CLIENTS"
); // Array<unknown[]>

const { rows: rows2 } = await my_client.queryArray<[number, string]>(
  "SELECT ID, NAME FROM CLIENTS"
); // Array<[number, string]>

Type Parameters

T extends Array<unknown>

Parameters

query: string
optional
args: QueryArguments

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]>

Type Parameters

T extends Array<unknown>

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}`;

Type Parameters

T extends Array<unknown>

Parameters

strings: TemplateStringsArray
...args: unknown[]