@photostructure/sqlite
    Preparing search index...

    Interface DatabaseSyncInstance

    Represents a SQLite database connection. This interface represents an instance of the DatabaseSync class.

    interface DatabaseSyncInstance {
        isOpen: boolean;
        isTransaction: boolean;
        "[dispose]"(): void;
        aggregate(name: string, options: AggregateOptions): void;
        applyChangeset(changeset: Buffer, options?: ChangesetApplyOptions): boolean;
        backup(
            path: string | Buffer<ArrayBufferLike> | URL,
            options?: {
                progress?: (
                    info: { remainingPages: number; totalPages: number },
                ) => void;
                rate?: number;
                source?: string;
                target?: string;
            },
        ): Promise<number>;
        close(): void;
        createSession(options?: SessionOptions): Session;
        enableLoadExtension(enable: boolean): void;
        exec(sql: string): void;
        function(name: string, func: Function): void;
        function(name: string, options: UserFunctionOptions, func: Function): void;
        loadExtension(path: string, entryPoint?: string): void;
        location(dbName?: string): null | string;
        open(configuration?: DatabaseSyncOptions): void;
        prepare(sql: string, options?: StatementOptions): StatementSyncInstance;
    }
    Index

    Properties

    isOpen: boolean

    Indicates whether the database connection is open.

    isTransaction: boolean

    Indicates whether a transaction is currently active.

    Methods

    • Dispose of the database resources using the explicit resource management protocol.

      Returns void

    • This method creates SQLite aggregate functions, wrapping sqlite3_create_window_function().

      Parameters

      • name: string

        The name of the SQLite aggregate function to create.

      • options: AggregateOptions

        Configuration object containing step function and other settings.

      Returns void

    • Apply a changeset to the database.

      Parameters

      • changeset: Buffer

        The changeset data to apply.

      • Optionaloptions: ChangesetApplyOptions

        Optional configuration for applying the changeset.

      Returns boolean

      true if successful, false if aborted.

    • Makes a backup of the database. This method abstracts the sqlite3_backup_init(), sqlite3_backup_step() and sqlite3_backup_finish() functions.

      The backed-up database can be used normally during the backup process. Mutations coming from the same connection will be reflected in the backup right away. However, mutations from other connections will cause the backup process to restart.

      Parameters

      • path: string | Buffer<ArrayBufferLike> | URL

        The path where the backup will be created. If the file already exists, the contents will be overwritten.

      • Optionaloptions: {
            progress?: (
                info: { remainingPages: number; totalPages: number },
            ) => void;
            rate?: number;
            source?: string;
            target?: string;
        }

        Optional configuration for the backup operation.

        • Optionalprogress?: (info: { remainingPages: number; totalPages: number }) => void

          Callback function that will be called with the number of pages copied and the total number of pages.

        • Optionalrate?: number

          Number of pages to be transmitted in each batch of the backup.

        • Optionalsource?: string

          Name of the source database. This can be 'main' (the default primary database) or any other database that have been added with ATTACH DATABASE.

        • Optionaltarget?: string

          Name of the target database. This can be 'main' (the default primary database) or any other database that have been added with ATTACH DATABASE.

      Returns Promise<number>

      A promise that resolves when the backup is completed and rejects if an error occurs.

      100
      
      'main'
      
      'main'
      
      // Basic backup
      await db.backup('./backup.db');
      // Backup with progress
      await db.backup('./backup.db', {
      rate: 10,
      progress: ({ totalPages, remainingPages }) => {
      console.log(`Progress: ${totalPages - remainingPages}/${totalPages}`);
      }
      });
    • Closes the database connection. This method should be called to ensure that the database connection is properly cleaned up. Once a database is closed, it cannot be used again.

      Returns void

    • Enables or disables the loading of SQLite extensions.

      Parameters

      • enable: boolean

        If true, enables extension loading. If false, disables it.

      Returns void

    • This method allows one or more SQL statements to be executed without returning any results. This is useful for commands like CREATE TABLE, INSERT, UPDATE, or DELETE.

      Parameters

      • sql: string

        The SQL statement(s) to execute.

      Returns void

    • This method creates SQLite user-defined functions, wrapping sqlite3_create_function_v2().

      Parameters

      • name: string

        The name of the SQLite function to create.

      • func: Function

        The JavaScript function to call when the SQLite function is invoked.

      Returns void

    • This method creates SQLite user-defined functions, wrapping sqlite3_create_function_v2().

      Parameters

      • name: string

        The name of the SQLite function to create.

      • options: UserFunctionOptions

        Optional configuration settings.

      • func: Function

        The JavaScript function to call when the SQLite function is invoked.

      Returns void

    • Loads an SQLite extension from the specified file path.

      Parameters

      • path: string

        The path to the extension library.

      • OptionalentryPoint: string

        Optional entry point function name. If not provided, uses the default entry point.

      Returns void

    • Returns the location of the database file. For attached databases, you can specify the database name. Returns null for in-memory databases.

      Parameters

      • OptionaldbName: string

        The name of the database. Defaults to 'main' (the primary database).

      Returns null | string

      The file path of the database, or null for in-memory databases.

    • Opens a database connection. This method is called automatically when creating a DatabaseSync instance, so typically should not be called directly.

      Parameters

      Returns void