Skip to main content
Module

x/postgres/client.ts>QueryClient#queryArray

PostgreSQL driver for Deno
Extremely Popular
Go to Latest
method QueryClient.prototype.queryArray
import { QueryClient } from "https://deno.land/x/postgres@v0.17.0/client.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 "./client.ts";

const my_client = new Client();

const {rows} = await my_client.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 "./client.ts";

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

It also allows you to execute prepared statements with template strings

import { Client } from "./client.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

query: string
optional
args: QueryArguments

Type Parameters

T extends Array<unknown>

Type Parameters

T extends Array<unknown>

Parameters

strings: TemplateStringsArray
...args: unknown[]