Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/sqlite/mod.ts>DB#query

Deno SQLite module
Latest
method DB.prototype.query
import { DB } from "https://deno.land/x/sqlite@v3.9.1/mod.ts";

Query the database and return all matching rows.

This is equivalent to calling all on a prepared query which is then immediately finalized.

The type parameter R may be supplied by the user to indicated the type for the rows returned by the query. Notice that the user is responsible for ensuring the correctness of the supplied type.

To avoid SQL injection, user-provided values should always be passed to the database through a query parameter.

See QueryParameterSet for documentation on how values can be bound to SQL statements.

See QueryParameter for documentation on how values are returned from the database.

Examples

const rows = db.query<[string, number]>("SELECT name, age FROM people WHERE city = ?", [city]);
// rows = [["Peter Parker", 21], ...]
const rows = db.query<[string, number]>(
  "SELECT name, age FROM people WHERE city = :city",
  { city },
 );
// rows = [["Peter Parker", 21], ...]

Type Parameters

optional
R extends Row = Row

Parameters

sql: string
optional
params: QueryParameterSet

Returns

Array<R>