SQLite for Nativescript
    Preparing search index...

    Interface SQLiteDatabase

    The query methods, shared by a database and by a transaction.

    interface SQLiteDatabase {
        filePath: string;
        isOpen: boolean;
        ready: Promise<void>;
        batch(
            statements: (string | BatchStatement | [string, SqliteParams?])[],
            options?: BatchOptions,
        ): Promise<BatchResult[]>;
        canLoadExtensions(): boolean;
        close(): Promise<void>;
        each(
            query: string,
            params: SqliteParams,
            callback: (error: Error, row: SqliteRow) => void,
            complete?: (error: Error, count: number) => void,
            options?: SqliteRequestOptions,
        ): Promise<number>;
        execute(query: string, params?: SqliteParams): Promise<ExecResult>;
        executeScript(script: string): Promise<void>;
        executeSync(query: string, params?: SqliteParams): ExecResult;
        get(
            query: string,
            params?: SqliteParams,
            options?: SqliteRequestOptions,
        ): Promise<SqliteRow>;
        getArray(
            query: string,
            params?: SqliteParams,
            options?: SqliteRequestOptions,
        ): Promise<any[]>;
        getArraySync(
            query: string,
            params?: SqliteParams,
            options?: SqliteRequestOptions,
        ): any[];
        getSqliteVersion(): string;
        getSync(
            query: string,
            params?: SqliteParams,
            options?: SqliteRequestOptions,
        ): SqliteRow;
        getVersion(): Promise<number>;
        loadExtension(path: string, entryPoint?: string): Promise<void>;
        select(
            query: string,
            params?: SqliteParams,
            options?: SqliteRequestOptions,
        ): Promise<SqliteRow[]>;
        selectArray(
            query: string,
            params?: SqliteParams,
            options?: SqliteRequestOptions,
        ): Promise<any[][]>;
        selectArraySync(
            query: string,
            params?: SqliteParams,
            options?: SqliteRequestOptions,
        ): any[][];
        selectSync(
            query: string,
            params?: SqliteParams,
            options?: SqliteRequestOptions,
        ): SqliteRow[];
        setVersion(version: number): Promise<void>;
        transaction<T = any>(
            action: (cancel: () => void, tx: SQLiteTransaction) => T | Promise<T>,
            options?: TransactionOptions,
        ): Promise<T>;
    }

    Hierarchy (View Summary)

    Implemented by

    Index

    Properties

    filePath: string
    isOpen: boolean

    true once the database is opened and until it is closed

    ready: Promise<void>

    resolves when the database is opened, rejects with the open error

    Methods

    • false when the engine in use cannot load extensions (loadExtension would reject)

      Returns boolean

    • Returns Promise<void>

    • streams rows in chunks, resolves with the number of rows

      Parameters

      Returns Promise<number>

    • run several statements separated by ;, without parameters

      Parameters

      • script: string

      Returns Promise<void>

    • Blocking variants: they wait for the database thread on the calling thread, saving the event loop round trip for small statements in a loop, and block it for the whole statement. Node-API binding only (NativeScript >= 9.1).

      Parameters

      Returns ExecResult

    • version of the SQLite library in use

      Returns string

    • Returns Promise<number>

    • Loads a SQLite extension into this connection; needs an engine that allows it (see canLoadExtensions). entryPoint defaults to the one SQLite derives from the file name (libfoo.so -> sqlite3_foo_init).

      Parameters

      • path: string
      • OptionalentryPoint: string

      Returns Promise<void>

    • Parameters

      • version: number

      Returns Promise<void>

    • Runs action in a transaction: COMMIT when it resolves, ROLLBACK when it throws or cancel() was called. Other calls made on this database meanwhile join it (use tx to be explicit); requests of other parts of the app wait for the end.

      Type Parameters

      • T = any

      Parameters

      Returns Promise<T>