Skip to main content

@db/sqlite@0.13.0
Built and signed on GitHub Actions

Works with
This package works with Deno
This package works with Deno
JSR Score100%
Downloads5,908/wk
Published4 months ago (0.13.0)

The fastest and correct module for SQLite3 in Deno

Classes

c
Database(
path: string | URL,
options?: DatabaseOpenOptions
)

Represents a SQLite3 database connection.

  • aggregate(
    name: string,
    options: AggregateFunctionOptions
    ): void

    Creates a new user-defined aggregate function.

  • autocommit(): boolean

    Whether autocommit is enabled. Enabled by default, can be disabled using BEGIN statement.

  • backup(
    dest: Database,
    name?: string,
    pages?
    ): void
    No documentation available
  • changes(): number

    Number of rows changed by the last executed statement.

  • close(): void

    Closes the database connection.

  • No documentation available
  • exec(
    sql: string,
    ...params: RestBindParameters
    ): number

    Simply executes the SQL statement (supports multiple statements separated by semicolon). Returns the number of changes made by last statement.

  • function(
    name: string,
    fn: CallableFunction,
    options?: FunctionOptions
    ): void

    Creates a new user-defined function.

  • inTransaction(): boolean

    Whether DB is in mid of a transaction

  • int64: boolean

    Whether to support BigInt columns. False by default, integers larger than 32 bit will be inaccurate.

  • lastInsertRowId(): number

    Gets last inserted Row ID

  • loadExtension(
    file: string,
    entryPoint?: string
    ): void

    Loads an SQLite extension library from the named file.

  • open(): boolean

    Whether DB connection is open

  • openBlob(options: BlobOpenOptions): SQLBlob

    Open a Blob for incremental I/O.

  • parseJson: boolean

    Whether to parse JSON columns as JS objects. True by default.

  • path(): string

    Path of the database file.

  • prepare<T extends object = Record<string, any>>(sql: string): Statement<T>

    Creates a new Prepared Statement from the given SQL statement.

  • run(
    sql: string,
    ...params: RestBindParameters
    ): number

    Alias for exec.

  • sql<T extends Record<string, any> = Record<string, any>>(
    strings: TemplateStringsArray,
    ...parameters: RestBindParameters
    ): T[]

    Safely execute SQL with parameters using a tagged template

  • totalChanges(): number

    Number of rows changed since the database connection was opened.

  • transaction<T extends (
    this: Transaction<T>,
    ...args: any[]
    ) => void
    >
    (fn: T): Transaction<T>

    Wraps a callback function in a transaction.

  • No documentation available
  • unsafeHandle(): Deno.PointerValue

    Unsafe Raw (pointer) to the sqlite object

c
SQLBlob(
db: Database,
options: BlobOpenOptions
)

Enumerates SQLite3 Blob opened for streamed I/O.

  • byteLength(): number

    Byte size of the Blob

  • close(): void

    Close the Blob. It must be called to prevent leaks.

  • readSync(
    offset: number,
    p: Uint8Array
    ): void

    Read from the Blob at given offset into a buffer (Uint8Array)

  • readable(): ReadableStream<Uint8Array>

    Obtains Web Stream for reading the Blob

  • writable(): WritableStream<Uint8Array>

    Obtains Web Stream for writing to the Blob

  • writeSync(
    offset: number,
    p: Uint8Array
    ): void

    Write a buffer (Uint8Array) at given offset in the Blob

c
SqliteError(
code?: number,
message?: string
)
No documentation available
  • name: string
    No documentation available
c
Statement<TStatement extends object = Record<string, any>>(
db: Database,
sql: string
)

Represents a prepared statement.

  • all<T extends object = TStatement>(...args: RestBindParameters): T[]

    Run the query and return the resulting rows where rows are objects mapping column name to their corresponding values.

  • bind(...params: RestBindParameters): this

    Bind parameters to the statement. This method can only be called once to set the parameters to be same throughout the statement. You cannot change the parameters after this method is called.

  • Number of parameters (to be) bound

  • bindParameterIndex(name: string): number

    Get bind parameter index by name

  • bindParameterName(i: number): string

    Get bind parameter name by index

  • columnNames(): string[]
    No documentation available
  • defaultInt64(): this
    No documentation available
  • No documentation available
  • disableInt64(): this
    No documentation available
  • No documentation available
  • enableInt64(): this
    No documentation available
  • No documentation available
  • expandedSql(): string

    SQL string including bindings

  • finalize(): void

    Free up the statement object.

  • get<T extends object = TStatement>(...params: RestBindParameters): T | undefined

    Fetch only first row as an object, if any.

  • getRowObject(): (
    h: Deno.PointerValue,
    int64: boolean,
    parseJson: boolean
    ) => any
    No documentation available
  • int64: boolean
    No documentation available
  • iter(...params: RestBindParameters): IterableIterator<any>

    Iterate over resultant rows from query.

  • parseJson: boolean
    No documentation available
  • readonly(): boolean

    Whether this statement doesn't make any direct changes to the DB

  • run(...args: RestBindParameters): number

    Simply run the query without retrieving any output there may be.

  • sql(): string

    The SQL string that we passed when creating statement

  • toString(): string

    Coerces the statement to a string, which in this case is expanded SQL.

  • unsafeHandle(): Deno.PointerValue

    Unsafe Raw (pointer) to the sqlite object

  • value<T extends Array<unknown>>(...params: RestBindParameters): T | undefined

    Fetch only first row as an array, if any.

  • values<T extends unknown[] = any[]>(...args: RestBindParameters): T[]

    Run the query and return the resulting rows where rows are array of columns.

Functions

f
isComplete(statement: string): boolean

Whether the given SQL statement is complete.

Interfaces

I

Options for user-defined aggregate functions.

  • final: (aggregate: any) => any
    No documentation available
  • start: any | (() => any)
    No documentation available
  • step: (
    aggregate: any,
    ...args: any[]
    ) => void
    No documentation available
I

Various options that can be configured when opening a Blob via Database#openBlob.

  • column: string

    Column name of the Blob Field

  • db: string

    Database to open Blob from, "main" by default.

  • readonly: boolean

    Whether to open Blob in readonly mode. True by default.

  • row: number

    Row ID of which column to select

  • table: string

    Table the Blob is in

I

Various options that can be configured when opening Database connection.

  • create: boolean

    Whether to create a new database file at specified path if one does not exist already. By default this is true.

  • Enable or disable extension loading

  • flags: number

    Raw SQLite C API flags. Specifying this ignores all other options.

  • int64: boolean

    Whether to support BigInt columns. False by default, integers larger than 32 bit will be inaccurate.

  • memory: boolean

    Opens an in-memory database.

  • parseJson: boolean

    Whether to parse JSON columns as JS objects. True by default.

  • readonly: boolean

    Whether to open database only in read-only mode. By default, this is false.

  • Apply agressive optimizations that are not possible with concurrent clients.

I

Options for user-defined functions.

Type Aliases

T
BindParameters = BindValue[] | Record<string, BindValue>
No documentation available
T
BindValue =
number
| string
| symbol
| bigint
| boolean
| null
| undefined
| Date
| Uint8Array
| BindValue[]
| { [key: string]: BindValue; }

Types that can be possibly serialized as SQLite bind values

T
RestBindParameters = BindValue[] | [BindParameters]
No documentation available
T
Transaction<T extends (...args: any[]) => void> =
((...args: Parameters<T>) => ReturnType<T>)
& { default: Transaction<T>; deferred: Transaction<T>; immediate: Transaction<T>; exclusive: Transaction<T>; database: Database; }

Transaction function created using Database#transaction.

Variables

v

SQLite source ID string

v

SQLite version string

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@db/sqlite

Import symbol

import * as mod from "@db/sqlite";
or

Import directly with a jsr specifier

import * as mod from "jsr:@db/sqlite";