Skip to main content
Module

x/sqlite3/mod.ts>Database#queryObject

Fast, native bindings to SQLite3 C API, using Deno FFI.
Go to Latest
method Database.prototype.queryObject
Re-export
import { Database } from "https://deno.land/x/sqlite3@0.4.4/mod.ts";

Executes an SQL query and returns the rows as objects.

Note: if you do not need the column names, consider calling queryArray instead. As this method does an extra FFI call to get the column names, it is more expensive than queryArray.

Example:

const users = db.queryObject<{
  id: number,
  username: string,
}>("select id, username from users");

// Using bind parameters
const [user] = db.queryObject<{
  id: number,
  username: string,
}>("select id, username from users where email = ?", email);

// Using template strings
const [user] = db.queryObject<{
 id: number,
 username: string,
}>`select id, username from users where email = ${email}`;

// Using named bind parameters
const [user] = db.queryObject<{
  id: number,
  username: string,
}>("select id, username from users where email = :email", { email });

Type Parameters

optional
T extends Record<string, unknown> = Record<string, any>

Parameters

strings: TemplateStringsArray

SQL query to execute.

...args: BindValue[]

Parameters to bind to the query.

Returns

T[]

Array of rows, where rows are objects mapping column names to values.

Type Parameters

optional
T extends Record<string, unknown> = Record<string, any>

Parameters

sql: string
...args: BindValue[]

Type Parameters

optional
T extends Record<string, unknown> = Record<string, any>

Parameters

sql: string
args: Record<string, BindValue>