CoolFace
Apppublic

Pinsave/counterstrike

sourceHugging Faceupdated 3mo agoView on Hugging Face
1likes
sqlite.d.ts689 linesDownload Raw Back to node
1/**2 * The `node:sqlite` module facilitates working with SQLite databases.3 * To access it:4 *5 * ```js6 * import sqlite from 'node:sqlite';7 * ```8 *9 * This module is only available under the `node:` scheme. The following will not10 * work:11 *12 * ```js13 * import sqlite from 'sqlite';14 * ```15 *16 * The following example shows the basic usage of the `node:sqlite` module to open17 * an in-memory database, write data to the database, and then read the data back.18 *19 * ```js20 * import { DatabaseSync } from 'node:sqlite';21 * const database = new DatabaseSync(':memory:');22 *23 * // Execute SQL statements from strings.24 * database.exec(`25 *   CREATE TABLE data(26 *     key INTEGER PRIMARY KEY,27 *     value TEXT28 *   ) STRICT29 * `);30 * // Create a prepared statement to insert data into the database.31 * const insert = database.prepare('INSERT INTO data (key, value) VALUES (?, ?)');32 * // Execute the prepared statement with bound values.33 * insert.run(1, 'hello');34 * insert.run(2, 'world');35 * // Create a prepared statement to read data from the database.36 * const query = database.prepare('SELECT * FROM data ORDER BY key');37 * // Execute the prepared statement and log the result set.38 * console.log(query.all());39 * // Prints: [ { key: 1, value: 'hello' }, { key: 2, value: 'world' } ]40 * ```41 * @since v22.5.042 * @experimental43 * @see [source](https://github.com/nodejs/node/blob/v24.x/lib/sqlite.js)44 */45declare module "node:sqlite" {46    type SQLInputValue = null | number | bigint | string | NodeJS.ArrayBufferView;47    type SQLOutputValue = null | number | bigint | string | Uint8Array;48    /** @deprecated Use `SQLInputValue` or `SQLOutputValue` instead. */49    type SupportedValueType = SQLOutputValue;50    interface DatabaseSyncOptions {51        /**52         * If `true`, the database is opened by the constructor. When53         * this value is `false`, the database must be opened via the `open()` method.54         * @since v22.5.055         * @default true56         */57        open?: boolean | undefined;58        /**59         * If `true`, foreign key constraints60         * are enabled. This is recommended but can be disabled for compatibility with61         * legacy database schemas. The enforcement of foreign key constraints can be62         * enabled and disabled after opening the database using63         * [`PRAGMA foreign_keys`](https://www.sqlite.org/pragma.html#pragma_foreign_keys).64         * @since v22.10.065         * @default true66         */67        enableForeignKeyConstraints?: boolean | undefined;68        /**69         * If `true`, SQLite will accept70         * [double-quoted string literals](https://www.sqlite.org/quirks.html#dblquote).71         * This is not recommended but can be72         * enabled for compatibility with legacy database schemas.73         * @since v22.10.074         * @default false75         */76        enableDoubleQuotedStringLiterals?: boolean | undefined;77        /**78         * If `true`, the database is opened in read-only mode.79         * If the database does not exist, opening it will fail.80         * @since v22.12.081         * @default false82         */83        readOnly?: boolean | undefined;84        /**85         * If `true`, the `loadExtension` SQL function86         * and the `loadExtension()` method are enabled.87         * You can call `enableLoadExtension(false)` later to disable this feature.88         * @since v22.13.089         * @default false90         */91        allowExtension?: boolean | undefined;92        /**93         * The [busy timeout](https://sqlite.org/c3ref/busy_timeout.html) in milliseconds. This is the maximum amount of94         * time that SQLite will wait for a database lock to be released before95         * returning an error.96         * @since v24.0.097         * @default 098         */99        timeout?: number | undefined;100    }101    interface CreateSessionOptions {102        /**103         * A specific table to track changes for. By default, changes to all tables are tracked.104         * @since v22.12.0105         */106        table?: string | undefined;107        /**108         * Name of the database to track. This is useful when multiple databases have been added using109         * [`ATTACH DATABASE`](https://www.sqlite.org/lang_attach.html).110         * @since v22.12.0111         * @default 'main'112         */113        db?: string | undefined;114    }115    interface ApplyChangesetOptions {116        /**117         * Skip changes that, when targeted table name is supplied to this function, return a truthy value.118         * By default, all changes are attempted.119         * @since v22.12.0120         */121        filter?: ((tableName: string) => boolean) | undefined;122        /**123         * A function that determines how to handle conflicts. The function receives one argument,124         * which can be one of the following values:125         *126         * * `SQLITE_CHANGESET_DATA`: A `DELETE` or `UPDATE` change does not contain the expected "before" values.127         * * `SQLITE_CHANGESET_NOTFOUND`: A row matching the primary key of the `DELETE` or `UPDATE` change does not exist.128         * * `SQLITE_CHANGESET_CONFLICT`: An `INSERT` change results in a duplicate primary key.129         * * `SQLITE_CHANGESET_FOREIGN_KEY`: Applying a change would result in a foreign key violation.130         * * `SQLITE_CHANGESET_CONSTRAINT`: Applying a change results in a `UNIQUE`, `CHECK`, or `NOT NULL` constraint131         * violation.132         *133         * The function should return one of the following values:134         *135         * * `SQLITE_CHANGESET_OMIT`: Omit conflicting changes.136         * * `SQLITE_CHANGESET_REPLACE`: Replace existing values with conflicting changes (only valid with137             `SQLITE_CHANGESET_DATA` or `SQLITE_CHANGESET_CONFLICT` conflicts).138         * * `SQLITE_CHANGESET_ABORT`: Abort on conflict and roll back the database.139         *140         * When an error is thrown in the conflict handler or when any other value is returned from the handler,141         * applying the changeset is aborted and the database is rolled back.142         *143         * **Default**: A function that returns `SQLITE_CHANGESET_ABORT`.144         * @since v22.12.0145         */146        onConflict?: ((conflictType: number) => number) | undefined;147    }148    interface FunctionOptions {149        /**150         * If `true`, the [`SQLITE_DETERMINISTIC`](https://www.sqlite.org/c3ref/c_deterministic.html) flag is151         * set on the created function.152         * @default false153         */154        deterministic?: boolean | undefined;155        /**156         * If `true`, the [`SQLITE_DIRECTONLY`](https://www.sqlite.org/c3ref/c_directonly.html) flag is set on157         * the created function.158         * @default false159         */160        directOnly?: boolean | undefined;161        /**162         * If `true`, integer arguments to `function`163         * are converted to `BigInt`s. If `false`, integer arguments are passed as164         * JavaScript numbers.165         * @default false166         */167        useBigIntArguments?: boolean | undefined;168        /**169         * If `true`, `function` may be invoked with any number of170         * arguments (between zero and171         * [`SQLITE_MAX_FUNCTION_ARG`](https://www.sqlite.org/limits.html#max_function_arg)). If `false`,172         * `function` must be invoked with exactly `function.length` arguments.173         * @default false174         */175        varargs?: boolean | undefined;176    }177    interface AggregateOptions<T extends SQLInputValue = SQLInputValue> extends FunctionOptions {178        /**179         * The identity value for the aggregation function. This value is used when the aggregation180         * function is initialized. When a `Function` is passed the identity will be its return value.181         */182        start: T | (() => T);183        /**184         * The function to call for each row in the aggregation. The185         * function receives the current state and the row value. The return value of186         * this function should be the new state.187         */188        step: (accumulator: T, ...args: SQLOutputValue[]) => T;189        /**190         * The function to call to get the result of the191         * aggregation. The function receives the final state and should return the192         * result of the aggregation.193         */194        result?: ((accumulator: T) => SQLInputValue) | undefined;195        /**196         * When this function is provided, the `aggregate` method will work as a window function.197         * The function receives the current state and the dropped row value. The return value of this function should be the198         * new state.199         */200        inverse?: ((accumulator: T, ...args: SQLOutputValue[]) => T) | undefined;201    }202    /**203     * This class represents a single [connection](https://www.sqlite.org/c3ref/sqlite3.html) to a SQLite database. All APIs204     * exposed by this class execute synchronously.205     * @since v22.5.0206     */207    class DatabaseSync implements Disposable {208        /**209         * Constructs a new `DatabaseSync` instance.210         * @param path The path of the database.211         * A SQLite database can be stored in a file or completely [in memory](https://www.sqlite.org/inmemorydb.html).212         * To use a file-backed database, the path should be a file path.213         * To use an in-memory database, the path should be the special name `':memory:'`.214         * @param options Configuration options for the database connection.215         */216        constructor(path: string | Buffer | URL, options?: DatabaseSyncOptions);217        /**218         * Registers a new aggregate function with the SQLite database. This method is a wrapper around219         * [`sqlite3_create_window_function()`](https://www.sqlite.org/c3ref/create_function.html).220         *221         * When used as a window function, the `result` function will be called multiple times.222         *223         * ```js224         * import { DatabaseSync } from 'node:sqlite';225         *226         * const db = new DatabaseSync(':memory:');227         * db.exec(`228         *   CREATE TABLE t3(x, y);229         *   INSERT INTO t3 VALUES ('a', 4),230         *                         ('b', 5),231         *                         ('c', 3),232         *                         ('d', 8),233         *                         ('e', 1);234         * `);235         *236         * db.aggregate('sumint', {237         *   start: 0,238         *   step: (acc, value) => acc + value,239         * });240         *241         * db.prepare('SELECT sumint(y) as total FROM t3').get(); // { total: 21 }242         * ```243         * @since v24.0.0244         * @param name The name of the SQLite function to create.245         * @param options Function configuration settings.246         */247        aggregate(name: string, options: AggregateOptions): void;248        aggregate<T extends SQLInputValue>(name: string, options: AggregateOptions<T>): void;249        /**250         * Closes the database connection. An exception is thrown if the database is not251         * open. This method is a wrapper around [`sqlite3_close_v2()`](https://www.sqlite.org/c3ref/close.html).252         * @since v22.5.0253         */254        close(): void;255        /**256         * Loads a shared library into the database connection. This method is a wrapper257         * around [`sqlite3_load_extension()`](https://www.sqlite.org/c3ref/load_extension.html). It is required to enable the258         * `allowExtension` option when constructing the `DatabaseSync` instance.259         * @since v22.13.0260         * @param path The path to the shared library to load.261         */262        loadExtension(path: string): void;263        /**264         * Enables or disables the `loadExtension` SQL function, and the `loadExtension()`265         * method. When `allowExtension` is `false` when constructing, you cannot enable266         * loading extensions for security reasons.267         * @since v22.13.0268         * @param allow Whether to allow loading extensions.269         */270        enableLoadExtension(allow: boolean): void;271        /**272         * This method is a wrapper around [`sqlite3_db_filename()`](https://sqlite.org/c3ref/db_filename.html)273         * @since v24.0.0274         * @param dbName Name of the database. This can be `'main'` (the default primary database) or any other275         * database that has been added with [`ATTACH DATABASE`](https://www.sqlite.org/lang_attach.html) **Default:** `'main'`.276         * @returns The location of the database file. When using an in-memory database,277         * this method returns null.278         */279        location(dbName?: string): string | null;280        /**281         * This method allows one or more SQL statements to be executed without returning282         * any results. This method is useful when executing SQL statements read from a283         * file. This method is a wrapper around [`sqlite3_exec()`](https://www.sqlite.org/c3ref/exec.html).284         * @since v22.5.0285         * @param sql A SQL string to execute.286         */287        exec(sql: string): void;288        /**289         * This method is used to create SQLite user-defined functions. This method is a290         * wrapper around [`sqlite3_create_function_v2()`](https://www.sqlite.org/c3ref/create_function.html).291         * @since v22.13.0292         * @param name The name of the SQLite function to create.293         * @param options Optional configuration settings for the function.294         * @param func The JavaScript function to call when the SQLite295         * function is invoked. The return value of this function should be a valid296         * SQLite data type: see297         * [Type conversion between JavaScript and SQLite](https://nodejs.org/docs/latest-v24.x/api/sqlite.html#type-conversion-between-javascript-and-sqlite).298         * The result defaults to `NULL` if the return value is `undefined`.299         */300        function(301            name: string,302            options: FunctionOptions,303            func: (...args: SQLOutputValue[]) => SQLInputValue,304        ): void;305        function(name: string, func: (...args: SQLOutputValue[]) => SQLInputValue): void;306        /**307         * Whether the database is currently open or not.308         * @since v22.15.0309         */310        readonly isOpen: boolean;311        /**312         * Whether the database is currently within a transaction. This method313         * is a wrapper around [`sqlite3_get_autocommit()`](https://sqlite.org/c3ref/get_autocommit.html).314         * @since v24.0.0315         */316        readonly isTransaction: boolean;317        /**318         * Opens the database specified in the `path` argument of the `DatabaseSync`constructor. This method should only be used when the database is not opened via319         * the constructor. An exception is thrown if the database is already open.320         * @since v22.5.0321         */322        open(): void;323        /**324         * Compiles a SQL statement into a [prepared statement](https://www.sqlite.org/c3ref/stmt.html). This method is a wrapper325         * around [`sqlite3_prepare_v2()`](https://www.sqlite.org/c3ref/prepare.html).326         * @since v22.5.0327         * @param sql A SQL string to compile to a prepared statement.328         * @return The prepared statement.329         */330        prepare(sql: string): StatementSync;331        /**332         * Creates and attaches a session to the database. This method is a wrapper around333         * [`sqlite3session_create()`](https://www.sqlite.org/session/sqlite3session_create.html) and334         * [`sqlite3session_attach()`](https://www.sqlite.org/session/sqlite3session_attach.html).335         * @param options The configuration options for the session.336         * @returns A session handle.337         * @since v22.12.0338         */339        createSession(options?: CreateSessionOptions): Session;340        /**341         * An exception is thrown if the database is not342         * open. This method is a wrapper around343         * [`sqlite3changeset_apply()`](https://www.sqlite.org/session/sqlite3changeset_apply.html).344         *345         * ```js346         * const sourceDb = new DatabaseSync(':memory:');347         * const targetDb = new DatabaseSync(':memory:');348         *349         * sourceDb.exec('CREATE TABLE data(key INTEGER PRIMARY KEY, value TEXT)');350         * targetDb.exec('CREATE TABLE data(key INTEGER PRIMARY KEY, value TEXT)');351         *352         * const session = sourceDb.createSession();353         *354         * const insert = sourceDb.prepare('INSERT INTO data (key, value) VALUES (?, ?)');355         * insert.run(1, 'hello');356         * insert.run(2, 'world');357         *358         * const changeset = session.changeset();359         * targetDb.applyChangeset(changeset);360         * // Now that the changeset has been applied, targetDb contains the same data as sourceDb.361         * ```362         * @param changeset A binary changeset or patchset.363         * @param options The configuration options for how the changes will be applied.364         * @returns Whether the changeset was applied successfully without being aborted.365         * @since v22.12.0366         */367        applyChangeset(changeset: Uint8Array, options?: ApplyChangesetOptions): boolean;368        /**369         * Closes the database connection. If the database connection is already closed370         * then this is a no-op.371         * @since v22.15.0372         * @experimental373         */374        [Symbol.dispose](): void;375    }376    /**377     * @since v22.12.0378     */379    interface Session {380        /**381         * Retrieves a changeset containing all changes since the changeset was created. Can be called multiple times.382         * An exception is thrown if the database or the session is not open. This method is a wrapper around383         * [`sqlite3session_changeset()`](https://www.sqlite.org/session/sqlite3session_changeset.html).384         * @returns Binary changeset that can be applied to other databases.385         * @since v22.12.0386         */387        changeset(): Uint8Array;388        /**389         * Similar to the method above, but generates a more compact patchset. See390         * [Changesets and Patchsets](https://www.sqlite.org/sessionintro.html#changesets_and_patchsets)391         * in the documentation of SQLite. An exception is thrown if the database or the session is not open. This method is a392         * wrapper around393         * [`sqlite3session_patchset()`](https://www.sqlite.org/session/sqlite3session_patchset.html).394         * @returns Binary patchset that can be applied to other databases.395         * @since v22.12.0396         */397        patchset(): Uint8Array;398        /**399         * Closes the session. An exception is thrown if the database or the session is not open. This method is a400         * wrapper around401         * [`sqlite3session_delete()`](https://www.sqlite.org/session/sqlite3session_delete.html).402         */403        close(): void;404    }405    interface StatementColumnMetadata {406        /**407         * The unaliased name of the column in the origin408         * table, or `null` if the column is the result of an expression or subquery.409         * This property is the result of [`sqlite3_column_origin_name()`](https://www.sqlite.org/c3ref/column_database_name.html).410         */411        column: string | null;412        /**413         * The unaliased name of the origin database, or414         * `null` if the column is the result of an expression or subquery. This415         * property is the result of [`sqlite3_column_database_name()`](https://www.sqlite.org/c3ref/column_database_name.html).416         */417        database: string | null;418        /**419         * The name assigned to the column in the result set of a420         * `SELECT` statement. This property is the result of421         * [`sqlite3_column_name()`](https://www.sqlite.org/c3ref/column_name.html).422         */423        name: string;424        /**425         * The unaliased name of the origin table, or `null` if426         * the column is the result of an expression or subquery. This property is the427         * result of [`sqlite3_column_table_name()`](https://www.sqlite.org/c3ref/column_database_name.html).428         */429        table: string | null;430        /**431         * The declared data type of the column, or `null` if the432         * column is the result of an expression or subquery. This property is the433         * result of [`sqlite3_column_decltype()`](https://www.sqlite.org/c3ref/column_decltype.html).434         */435        type: string | null;436    }437    interface StatementResultingChanges {438        /**439         * The number of rows modified, inserted, or deleted by the most recently completed `INSERT`, `UPDATE`, or `DELETE` statement.440         * This field is either a number or a `BigInt` depending on the prepared statement's configuration.441         * This property is the result of [`sqlite3_changes64()`](https://www.sqlite.org/c3ref/changes.html).442         */443        changes: number | bigint;444        /**445         * The most recently inserted rowid.446         * This field is either a number or a `BigInt` depending on the prepared statement's configuration.447         * This property is the result of [`sqlite3_last_insert_rowid()`](https://www.sqlite.org/c3ref/last_insert_rowid.html).448         */449        lastInsertRowid: number | bigint;450    }451    /**452     * This class represents a single [prepared statement](https://www.sqlite.org/c3ref/stmt.html). This class cannot be453     * instantiated via its constructor. Instead, instances are created via the`database.prepare()` method. All APIs exposed by this class execute454     * synchronously.455     *456     * A prepared statement is an efficient binary representation of the SQL used to457     * create it. Prepared statements are parameterizable, and can be invoked multiple458     * times with different bound values. Parameters also offer protection against [SQL injection](https://en.wikipedia.org/wiki/SQL_injection) attacks. For these reasons, prepared statements are459     * preferred460     * over hand-crafted SQL strings when handling user input.461     * @since v22.5.0462     */463    class StatementSync {464        private constructor();465        /**466         * This method executes a prepared statement and returns all results as an array of467         * objects. If the prepared statement does not return any results, this method468         * returns an empty array. The prepared statement [parameters are bound](https://www.sqlite.org/c3ref/bind_blob.html) using469         * the values in `namedParameters` and `anonymousParameters`.470         * @since v22.5.0471         * @param namedParameters An optional object used to bind named parameters. The keys of this object are used to configure the mapping.472         * @param anonymousParameters Zero or more values to bind to anonymous parameters.473         * @return An array of objects. Each object corresponds to a row returned by executing the prepared statement. The keys and values of each object correspond to the column names and values of474         * the row.475         */476        all(...anonymousParameters: SQLInputValue[]): Record<string, SQLOutputValue>[];477        all(478            namedParameters: Record<string, SQLInputValue>,479            ...anonymousParameters: SQLInputValue[]480        ): Record<string, SQLOutputValue>[];481        /**482         * This method is used to retrieve information about the columns returned by the483         * prepared statement.484         * @since v23.11.0485         * @returns An array of objects. Each object corresponds to a column486         * in the prepared statement, and contains the following properties:487         */488        columns(): StatementColumnMetadata[];489        /**490         * The source SQL text of the prepared statement with parameter491         * placeholders replaced by the values that were used during the most recent492         * execution of this prepared statement. This property is a wrapper around493         * [`sqlite3_expanded_sql()`](https://www.sqlite.org/c3ref/expanded_sql.html).494         * @since v22.5.0495         */496        readonly expandedSQL: string;497        /**498         * This method executes a prepared statement and returns the first result as an499         * object. If the prepared statement does not return any results, this method500         * returns `undefined`. The prepared statement [parameters are bound](https://www.sqlite.org/c3ref/bind_blob.html) using the501         * values in `namedParameters` and `anonymousParameters`.502         * @since v22.5.0503         * @param namedParameters An optional object used to bind named parameters. The keys of this object are used to configure the mapping.504         * @param anonymousParameters Zero or more values to bind to anonymous parameters.505         * @return An object corresponding to the first row returned by executing the prepared statement. The keys and values of the object correspond to the column names and values of the row. If no506         * rows were returned from the database then this method returns `undefined`.507         */508        get(...anonymousParameters: SQLInputValue[]): Record<string, SQLOutputValue> | undefined;509        get(510            namedParameters: Record<string, SQLInputValue>,511            ...anonymousParameters: SQLInputValue[]512        ): Record<string, SQLOutputValue> | undefined;513        /**514         * This method executes a prepared statement and returns an iterator of515         * objects. If the prepared statement does not return any results, this method516         * returns an empty iterator. The prepared statement [parameters are bound](https://www.sqlite.org/c3ref/bind_blob.html) using517         * the values in `namedParameters` and `anonymousParameters`.518         * @since v22.13.0519         * @param namedParameters An optional object used to bind named parameters.520         * The keys of this object are used to configure the mapping.521         * @param anonymousParameters Zero or more values to bind to anonymous parameters.522         * @returns An iterable iterator of objects. Each object corresponds to a row523         * returned by executing the prepared statement. The keys and values of each524         * object correspond to the column names and values of the row.525         */526        iterate(...anonymousParameters: SQLInputValue[]): NodeJS.Iterator<Record<string, SQLOutputValue>>;527        iterate(528            namedParameters: Record<string, SQLInputValue>,529            ...anonymousParameters: SQLInputValue[]530        ): NodeJS.Iterator<Record<string, SQLOutputValue>>;531        /**532         * This method executes a prepared statement and returns an object summarizing the533         * resulting changes. The prepared statement [parameters are bound](https://www.sqlite.org/c3ref/bind_blob.html) using the534         * values in `namedParameters` and `anonymousParameters`.535         * @since v22.5.0536         * @param namedParameters An optional object used to bind named parameters. The keys of this object are used to configure the mapping.537         * @param anonymousParameters Zero or more values to bind to anonymous parameters.538         */539        run(...anonymousParameters: SQLInputValue[]): StatementResultingChanges;540        run(541            namedParameters: Record<string, SQLInputValue>,542            ...anonymousParameters: SQLInputValue[]543        ): StatementResultingChanges;544        /**545         * The names of SQLite parameters begin with a prefix character. By default,`node:sqlite` requires that this prefix character is present when binding546         * parameters. However, with the exception of dollar sign character, these547         * prefix characters also require extra quoting when used in object keys.548         *549         * To improve ergonomics, this method can be used to also allow bare named550         * parameters, which do not require the prefix character in JavaScript code. There551         * are several caveats to be aware of when enabling bare named parameters:552         *553         * * The prefix character is still required in SQL.554         * * The prefix character is still allowed in JavaScript. In fact, prefixed names555         * will have slightly better binding performance.556         * * Using ambiguous named parameters, such as `$k` and `@k`, in the same prepared557         * statement will result in an exception as it cannot be determined how to bind558         * a bare name.559         * @since v22.5.0560         * @param enabled Enables or disables support for binding named parameters without the prefix character.561         */562        setAllowBareNamedParameters(enabled: boolean): void;563        /**564         * By default, if an unknown name is encountered while binding parameters, an565         * exception is thrown. This method allows unknown named parameters to be ignored.566         * @since v22.15.0567         * @param enabled Enables or disables support for unknown named parameters.568         */569        setAllowUnknownNamedParameters(enabled: boolean): void;570        /**571         * When reading from the database, SQLite `INTEGER`s are mapped to JavaScript572         * numbers by default. However, SQLite `INTEGER`s can store values larger than573         * JavaScript numbers are capable of representing. In such cases, this method can574         * be used to read `INTEGER` data using JavaScript `BigInt`s. This method has no575         * impact on database write operations where numbers and `BigInt`s are both576         * supported at all times.577         * @since v22.5.0578         * @param enabled Enables or disables the use of `BigInt`s when reading `INTEGER` fields from the database.579         */580        setReadBigInts(enabled: boolean): void;581        /**582         * The source SQL text of the prepared statement. This property is a583         * wrapper around [`sqlite3_sql()`](https://www.sqlite.org/c3ref/expanded_sql.html).584         * @since v22.5.0585         */586        readonly sourceSQL: string;587    }588    interface BackupOptions {589        /**590         * Name of the source database. This can be `'main'` (the default primary database) or any other591         * database that have been added with [`ATTACH DATABASE`](https://www.sqlite.org/lang_attach.html)592         * @default 'main'593         */594        source?: string | undefined;595        /**596         * Name of the target database. This can be `'main'` (the default primary database) or any other597         * database that have been added with [`ATTACH DATABASE`](https://www.sqlite.org/lang_attach.html)598         * @default 'main'599         */600        target?: string | undefined;601        /**602         * Number of pages to be transmitted in each batch of the backup.603         * @default 100604         */605        rate?: number | undefined;606        /**607         * Callback function that will be called with the number of pages copied and the total number of608         * pages.609         */610        progress?: ((progressInfo: BackupProgressInfo) => void) | undefined;611    }612    interface BackupProgressInfo {613        totalPages: number;614        remainingPages: number;615    }616    /**617     * This method makes a database backup. This method abstracts the618     * [`sqlite3_backup_init()`](https://www.sqlite.org/c3ref/backup_finish.html#sqlite3backupinit),619     * [`sqlite3_backup_step()`](https://www.sqlite.org/c3ref/backup_finish.html#sqlite3backupstep)620     * and [`sqlite3_backup_finish()`](https://www.sqlite.org/c3ref/backup_finish.html#sqlite3backupfinish) functions.621     *622     * The backed-up database can be used normally during the backup process. Mutations coming from the same connection - same623     * `DatabaseSync` - object will be reflected in the backup right away. However, mutations from other connections will cause624     * the backup process to restart.625     *626     * ```js627     * import { backup, DatabaseSync } from 'node:sqlite';628     *629     * const sourceDb = new DatabaseSync('source.db');630     * const totalPagesTransferred = await backup(sourceDb, 'backup.db', {631     *   rate: 1, // Copy one page at a time.632     *   progress: ({ totalPages, remainingPages }) => {633     *     console.log('Backup in progress', { totalPages, remainingPages });634     *   },635     * });636     *637     * console.log('Backup completed', totalPagesTransferred);638     * ```639     * @since v23.8.0640     * @param sourceDb The database to backup. The source database must be open.641     * @param path The path where the backup will be created. If the file already exists,642     * the contents will be overwritten.643     * @param options Optional configuration for the backup. The644     * following properties are supported:645     * @returns A promise that resolves when the backup is completed and rejects if an error occurs.646     */647    function backup(sourceDb: DatabaseSync, path: string | Buffer | URL, options?: BackupOptions): Promise<void>;648    /**649     * @since v22.13.0650     */651    namespace constants {652        /**653         * The conflict handler is invoked with this constant when processing a DELETE or UPDATE change if a row with the required PRIMARY KEY fields is present in the database, but one or more other (non primary-key) fields modified by the update do not contain the expected "before" values.654         * @since v22.14.0655         */656        const SQLITE_CHANGESET_DATA: number;657        /**658         * The conflict handler is invoked with this constant when processing a DELETE or UPDATE change if a row with the required PRIMARY KEY fields is not present in the database.659         * @since v22.14.0660         */661        const SQLITE_CHANGESET_NOTFOUND: number;662        /**663         * This constant is passed to the conflict handler while processing an INSERT change if the operation would result in duplicate primary key values.664         * @since v22.14.0665         */666        const SQLITE_CHANGESET_CONFLICT: number;667        /**668         * If foreign key handling is enabled, and applying a changeset leaves the database in a state containing foreign key violations, the conflict handler is invoked with this constant exactly once before the changeset is committed. If the conflict handler returns `SQLITE_CHANGESET_OMIT`, the changes, including those that caused the foreign key constraint violation, are committed. Or, if it returns `SQLITE_CHANGESET_ABORT`, the changeset is rolled back.669         * @since v22.14.0670         */671        const SQLITE_CHANGESET_FOREIGN_KEY: number;672        /**673         * Conflicting changes are omitted.674         * @since v22.12.0675         */676        const SQLITE_CHANGESET_OMIT: number;677        /**678         * Conflicting changes replace existing values. Note that this value can only be returned when the type of conflict is either `SQLITE_CHANGESET_DATA` or `SQLITE_CHANGESET_CONFLICT`.679         * @since v22.12.0680         */681        const SQLITE_CHANGESET_REPLACE: number;682        /**683         * Abort when a change encounters a conflict and roll back database.684         * @since v22.12.0685         */686        const SQLITE_CHANGESET_ABORT: number;687    }688}689