Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/stowrage/deps.ts>DB#prepareQuery

Stowre all the thing's you like
Latest
method DB.prototype.prepareQuery
import { DB } from "https://deno.land/x/stowrage@v0.4.2/deps.ts";

DB.prepareQuery

This is similar to query(), with the difference that the returned function can be called multiple times (with different values to bind each time).

Using a prepared query instead of query() will improve performance if the query is issued a lot, e.g. when writing a web server, the queries used by the server could be prepared once and then used through it's runtime.

A prepared query must be finalized when it is no longer in used by calling query.finalize(). So the complete lifetime of a query would look like this:

// once
const query = db.prepareQuery("INSERT INTO messages (message, author) VALUES (?, ?)");

// many times
query([messageValueOne, authorValueOne]);
query([messageValueTwo, authorValueTwo]);
// ...

// once
query.finalize();

Parameters

sql: string