Skip to main content
Module

x/sqlite3/mod.ts>Database#prepare

Fastest & correct JavaScript bindings to SQLite3 C API, using Deno FFI.
Go to Latest
method Database.prototype.prepare
Re-export
import { Database } from "https://deno.land/x/sqlite3@v0.5.3/mod.ts";

Creates a new Prepared Statement from the given SQL statement.

Example:

const stmt = db.prepare("SELECT * FROM mytable WHERE id = ?");

for (const row of stmt.all(1)) {
  console.log(row);
}

Bind parameters can be either provided as an array of values, or as an object mapping the parameter name to the value.

Example:

const stmt = db.prepare("SELECT * FROM mytable WHERE id = ?");
const row = stmt.get(1);

// or

const stmt = db.prepare("SELECT * FROM mytable WHERE id = :id");
const row = stmt.get({ id: 1 });

Statements are automatically freed once GC catches them, however you can also manually free using finalize method.

Parameters

sql: string

SQL statement string

Returns

Statement object