Skip to main content
Module

x/denodb/deps.ts>SQLiteClient

MySQL, SQLite, MariaDB, PostgreSQL and MongoDB ORM for Deno
Go to Latest
class SQLiteClient
import { SQLiteClient } from "https://deno.land/x/denodb@v1.0.40/deps.ts";

Constructors

new
SQLiteClient(path?: string, options?: SqliteOptions)

Create a new database. The file at the given path will be opened with the mode specified in options. The default mode is create.

If no path is given, or if the memory option is set, the database is opened in memory.

Properties

private
_open: boolean
private
_statements: Set<StatementPtr>
private
_wasm: Wasm
readonly
changes: number

Return the number of rows modified, inserted or deleted by the most recently completed query. This corresponds to the SQLite function sqlite3_changes.

readonly
lastInsertRowId: number

Get last inserted row id. This corresponds to the SQLite function sqlite3_last_insert_rowid.

Before a row is inserted for the first time (since the database was opened), this returns 0.

readonly
totalChanges: number

Return the number of rows modified, inserted or deleted since the database was opened. This corresponds to the SQLite function sqlite3_total_changes.

Methods

close(force?)

Close the database. This must be called if the database is no longer used to avoid leaking open file descriptors.

If force is specified, any active PreparedQuery will be finalized. Otherwise, this throws if there are active queries.

close may safely be called multiple times.

prepareQuery<R extends Row = Row, O extends RowObject = RowObject, P extends QueryParameterSet = QueryParameterSet>(sql: string): PreparedQuery<R, O, P>

Prepares the given SQL query, so that it can be run multiple times and potentially with different parameters.

If a query will be issued a lot, this is more efficient than using query. A prepared query also provides more control over how the query is run, as well as access to meta-data about the issued query.

The returned PreparedQuery object must be finalized by calling its finalize method once it is no longer needed.

Typing Queries

Prepared query objects accept three type parameters to specify precise types for returned data and query parameters.

The first type parameter R indicates the tuple type for rows returned by the query.

The second type parameter O indicates the record type for rows returned as entries (mappings from column names to values).

The third type parameter P indicates the type this query accepts as parameters.

Note, that the correctness of those types must be guaranteed by the caller of this function.

query<R extends Row = Row>(sql: string, params?: QueryParameterSet): Array<R>

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.

queryEntries<O extends RowObject = RowObject>(sql: string, params?: QueryParameterSet): Array<O>

Like query except each row is returned as an object containing key-value pairs.