aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-05-16 18:58:11 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-05-16 18:58:11 -0700
commitbd1e64b9b1c5bbbd14893eca2e2508fc8deefd22 (patch)
treec96da93c95a2212d6ec390bad8b760e56ff40677
parent31f30503563ee354c48330c64a262c03837b0c1a (diff)
downloadbun-bd1e64b9b1c5bbbd14893eca2e2508fc8deefd22.tar.gz
bun-bd1e64b9b1c5bbbd14893eca2e2508fc8deefd22.tar.zst
bun-bd1e64b9b1c5bbbd14893eca2e2508fc8deefd22.zip
Fix type errors
Diffstat (limited to '')
-rw-r--r--packages/bun-types/package.json2
-rw-r--r--packages/bun-types/types.d.ts905
-rw-r--r--types/bun/sqlite.d.ts12
3 files changed, 909 insertions, 10 deletions
diff --git a/packages/bun-types/package.json b/packages/bun-types/package.json
index 5b6b10ace..a0d4f40a3 100644
--- a/packages/bun-types/package.json
+++ b/packages/bun-types/package.json
@@ -1,6 +1,6 @@
{
"name": "bun-types",
- "version": "0.0.79",
+ "version": "0.0.83",
"description": "Type definitions for bun.js",
"types": "types.d.ts",
"files": [
diff --git a/packages/bun-types/types.d.ts b/packages/bun-types/types.d.ts
index bcc0fd0d0..50820f4e9 100644
--- a/packages/bun-types/types.d.ts
+++ b/packages/bun-types/types.d.ts
@@ -365,7 +365,7 @@ declare module "bun" {
* const query = UserQuery;
* ```
*/
- macros: MacroMap;
+ macros?: MacroMap;
}
/**
@@ -403,7 +403,27 @@ declare module "bun" {
* @param code The code to transpile
*
*/
- transformSync(code: StringOrBuffer, loader?: JavaScriptLoader): string;
+ transformSync(
+ code: StringOrBuffer,
+ loader: JavaScriptLoader,
+ ctx: object
+ ): string;
+ /**
+ * Transpile code from TypeScript or JSX into valid JavaScript.
+ * This function does not resolve imports.
+ * @param code The code to transpile
+ * @param ctx An object to pass to macros
+ *
+ */
+ transformSync(code: StringOrBuffer, ctx: object): string;
+
+ /**
+ * Transpile code from TypeScript or JSX into valid JavaScript.
+ * This function does not resolve imports.
+ * @param code The code to transpile
+ *
+ */
+ transformSync(code: StringOrBuffer, loader: JavaScriptLoader): string;
/**
* Get a list of import paths and paths from a TypeScript, JSX, TSX, or JavaScript file.
@@ -1472,6 +1492,17 @@ declare module "bun:ffi" {
* ```
*/
returns?: FFITypeOrString;
+
+ /**
+ * Function pointer to the native function
+ *
+ * If provided, instead of using dlsym() to lookup the function, Bun will use this instead.
+ * This pointer should not be null (0).
+ *
+ * This is useful if the library has already been loaded
+ * or if the module is also using Node-API.
+ */
+ ptr?: number | bigint;
}
type Symbols = Record<string, FFIFunction>;
@@ -1505,7 +1536,124 @@ declare module "bun:ffi" {
close(): void;
}
- export function dlopen(libraryName: string, symbols: Symbols): Library;
+ /**
+ * Open a library using `"bun:ffi"`
+ *
+ * @param name The name of the library or file path. This will be passed to `dlopen()`
+ * @param symbols Map of symbols to load where the key is the symbol name and the value is the {@link FFIFunction}
+ *
+ * @example
+ *
+ * ```js
+ * import {dlopen} from 'bun:ffi';
+ *
+ * const lib = dlopen("duckdb.dylib", {
+ * get_version: {
+ * returns: "cstring",
+ * args: [],
+ * },
+ * });
+ * lib.symbols.get_version();
+ * // "1.0.0"
+ * ```
+ *
+ * This is powered by just-in-time compiling C wrappers
+ * that convert JavaScript types to C types and back. Internally,
+ * bun uses [tinycc](https://github.com/TinyCC/tinycc), so a big thanks
+ * goes to Fabrice Bellard and TinyCC maintainers for making this possible.
+ *
+ */
+ export function dlopen(name: string, symbols: Symbols): Library;
+
+ /**
+ * Turn a native library's function pointer into a JavaScript function
+ *
+ * Libraries using Node-API & bun:ffi in the same module could use this to skip an extra dlopen() step.
+ *
+ * @param fn {@link FFIFunction} declaration. `ptr` is required
+ *
+ * @example
+ *
+ * ```js
+ * import {CFunction} from 'bun:ffi';
+ *
+ * const getVersion = new CFunction({
+ * returns: "cstring",
+ * args: [],
+ * ptr: myNativeLibraryGetVersion,
+ * });
+ * getVersion();
+ * getVersion.close();
+ * ```
+ *
+ * This is powered by just-in-time compiling C wrappers
+ * that convert JavaScript types to C types and back. Internally,
+ * bun uses [tinycc](https://github.com/TinyCC/tinycc), so a big thanks
+ * goes to Fabrice Bellard and TinyCC maintainers for making this possible.
+ *
+ */
+ export function CFunction(
+ fn: FFIFunction & { ptr: number | bigint }
+ ): CallableFunction & {
+ /**
+ * Free the memory allocated by the wrapping function
+ */
+ close(): void;
+ };
+
+ /**
+ * Link a map of symbols to JavaScript functions
+ *
+ * This lets you use native libraries that were already loaded somehow. You usually will want {@link dlopen} instead.
+ *
+ * You could use this with Node-API to skip loading a second time.
+ *
+ * @param symbols Map of symbols to load where the key is the symbol name and the value is the {@link FFIFunction}
+ *
+ * @example
+ *
+ * ```js
+ * import { linkSymbols } from "bun:ffi";
+ *
+ * const [majorPtr, minorPtr, patchPtr] = getVersionPtrs();
+ *
+ * const lib = linkSymbols({
+ * // Unlike with dlopen(), the names here can be whatever you want
+ * getMajor: {
+ * returns: "cstring",
+ * args: [],
+ *
+ * // Since this doesn't use dlsym(), you have to provide a valid ptr
+ * // That ptr could be a number or a bigint
+ * // An invalid pointer will crash your program.
+ * ptr: majorPtr,
+ * },
+ * getMinor: {
+ * returns: "cstring",
+ * args: [],
+ * ptr: minorPtr,
+ * },
+ * getPatch: {
+ * returns: "cstring",
+ * args: [],
+ * ptr: patchPtr,
+ * },
+ * });
+ *
+ * const [major, minor, patch] = [
+ * lib.symbols.getMajor(),
+ * lib.symbols.getMinor(),
+ * lib.symbols.getPatch(),
+ * ];
+ * ```
+ *
+ * This is powered by just-in-time compiling C wrappers
+ * that convert JavaScript types to C types and back. Internally,
+ * bun uses [tinycc](https://github.com/TinyCC/tinycc), so a big thanks
+ * goes to Fabrice Bellard and TinyCC maintainers for making this possible.
+ *
+ */
+ export function linkSymbols(symbols: Symbols): Library;
/**
* Read a pointer as a {@link Buffer}
@@ -1680,6 +1828,757 @@ declare module "bun:ffi" {
}
+// ./sqlite.d.ts
+
+/**
+ * Fast SQLite3 driver for Bun.js
+ * @since v0.0.83
+ *
+ * @example
+ * ```ts
+ * import { Database } from 'bun:sqlite';
+ *
+ * var db = new Database('app.db');
+ * db.query('SELECT * FROM users WHERE name = ?').all('John');
+ * // => [{ id: 1, name: 'John' }]
+ * ```
+ *
+ * The following types can be used when binding parameters:
+ *
+ * | JavaScript type | SQLite type |
+ * | -------------- | ----------- |
+ * | `string` | `TEXT` |
+ * | `number` | `INTEGER` or `DECIMAL` |
+ * | `boolean` | `INTEGER` (1 or 0) |
+ * | `Uint8Array` | `BLOB` |
+ * | `Buffer` | `BLOB` |
+ * | `bigint` | `INTEGER` |
+ * | `null` | `NULL` |
+ */
+declare module "bun:sqlite" {
+ export class Database {
+ /**
+ * Open or create a SQLite3 database
+ *
+ * @param filename The filename of the database to open. Pass an empty string (`""`) or `":memory:"` for an in-memory database.
+ * @param options defaults to `{readwrite: true, create: true}`. If a number, then it's treated as `SQLITE_OPEN_*` constant flags.
+ *
+ * @example
+ *
+ * ```ts
+ * const db = new Database("mydb.sqlite");
+ * db.run("CREATE TABLE foo (bar TEXT)");
+ * db.run("INSERT INTO foo VALUES (?)", "baz");
+ * console.log(db.query("SELECT * FROM foo").all());
+ * ```
+ *
+ * @example
+ *
+ * Open an in-memory database
+ *
+ * ```ts
+ * const db = new Database(":memory:");
+ * db.run("CREATE TABLE foo (bar TEXT)");
+ * db.run("INSERT INTO foo VALUES (?)", "hiiiiii");
+ * console.log(db.query("SELECT * FROM foo").all());
+ * ```
+ *
+ * @example
+ *
+ * Open read-only
+ *
+ * ```ts
+ * const db = new Database("mydb.sqlite", {readonly: true});
+ * ```
+ */
+ constructor(
+ filename: string,
+ options?:
+ | number
+ | {
+ /**
+ * Open the database as read-only (no write operations, no create).
+ *
+ * Equivalent to {@link constants.SQLITE_OPEN_READONLY}
+ */
+ readonly?: boolean;
+ /**
+ * Allow creating a new database
+ *
+ * Equivalent to {@link constants.SQLITE_OPEN_CREATE}
+ */
+ create?: boolean;
+ /**
+ * Open the database as read-write
+ *
+ * Equivalent to {@link constants.SQLITE_OPEN_READWRITE}
+ */
+ readwrite?: boolean;
+ }
+ );
+
+ /**
+ * This is an alias of `new Database()`
+ *
+ * See {@link Database}
+ */
+ static open(
+ filename: string,
+ options?:
+ | number
+ | {
+ /**
+ * Open the database as read-only (no write operations, no create).
+ *
+ * Equivalent to {@link constants.SQLITE_OPEN_READONLY}
+ */
+ readonly?: boolean;
+ /**
+ * Allow creating a new database
+ *
+ * Equivalent to {@link constants.SQLITE_OPEN_CREATE}
+ */
+ create?: boolean;
+ /**
+ * Open the database as read-write
+ *
+ * Equivalent to {@link constants.SQLITE_OPEN_READWRITE}
+ */
+ readwrite?: boolean;
+ }
+ ): Database;
+
+ /**
+ * Execute a SQL query **without returning any results**.
+ *
+ * This does not cache the query, so if you want to run a query multiple times, you should use {@link prepare} instead.
+ *
+ * @example
+ * ```ts
+ * db.run("CREATE TABLE foo (bar TEXT)");
+ * db.run("INSERT INTO foo VALUES (?)", "baz");
+ * ```
+ *
+ * Useful for queries like:
+ * - `CREATE TABLE`
+ * - `INSERT INTO`
+ * - `UPDATE`
+ * - `DELETE FROM`
+ * - `DROP TABLE`
+ * - `PRAGMA`
+ * - `ATTACH DATABASE`
+ * - `DETACH DATABASE`
+ * - `REINDEX`
+ * - `VACUUM`
+ * - `EXPLAIN ANALYZE`
+ * - `CREATE INDEX`
+ * - `CREATE TRIGGER`
+ * - `CREATE VIEW`
+ * - `CREATE VIRTUAL TABLE`
+ * - `CREATE TEMPORARY TABLE`
+ *
+ * @param sql The SQL query to run
+ *
+ * @param bindings Optional bindings for the query
+ *
+ * @returns `Database` instance
+ *
+ * Under the hood, this calls `sqlite3_prepare_v3` followed by `sqlite3_step` and `sqlite3_finalize`.
+ *
+ * * The following types can be used when binding parameters:
+ *
+ * | JavaScript type | SQLite type |
+ * | -------------- | ----------- |
+ * | `string` | `TEXT` |
+ * | `number` | `INTEGER` or `DECIMAL` |
+ * | `boolean` | `INTEGER` (1 or 0) |
+ * | `Uint8Array` | `BLOB` |
+ * | `Buffer` | `BLOB` |
+ * | `bigint` | `INTEGER` |
+ * | `null` | `NULL` |
+ */
+ run<ParamsType = SQLQueryBindings>(
+ sqlQuery: string,
+ ...bindings: ParamsType
+ ): void;
+ /**
+ This is an alias of {@link Database.prototype.run}
+ */
+ exec<ParamsType = SQLQueryBindings>(
+ sqlQuery: string,
+ ...bindings: ParamsType
+ ): void;
+
+ /**
+ * Compile a SQL query and return a {@link Statement} object. This is the
+ * same as {@link prepare} except that it caches the compiled query.
+ *
+ * This **does not execute** the query, but instead prepares it for later
+ * execution and caches the compiled query if possible.
+ *
+ * @example
+ * ```ts
+ * // compile the query
+ * const stmt = db.query("SELECT * FROM foo WHERE bar = ?");
+ * // run the query
+ * stmt.all("baz");
+ *
+ * // run the query again
+ * stmt.all();
+ * ```
+ *
+ * @param sql The SQL query to compile
+ *
+ * @returns `Statment` instance
+ *
+ * Under the hood, this calls `sqlite3_prepare_v3`.
+ *
+ */
+ query<ParamsType = SQLQueryBindings, ReturnType = any>(
+ sqlQuery: string
+ ): Statement<ParamsType, ReturnType>;
+
+ /**
+ * Compile a SQL query and return a {@link Statement} object.
+ *
+ * This does not cache the compiled query and does not execute the query.
+ *
+ * @example
+ * ```ts
+ * // compile the query
+ * const stmt = db.query("SELECT * FROM foo WHERE bar = ?");
+ * // run the query
+ * stmt.all("baz");
+ * ```
+ *
+ * @param sql The SQL query to compile
+ * @param params Optional bindings for the query
+ *
+ * @returns `Statment` instance
+ *
+ * Under the hood, this calls `sqlite3_prepare_v3`.
+ *
+ */
+ prepare<ParamsType = SQLQueryBindings, ReturnType = any>(
+ sql: string,
+ ...params: ParamsType[]
+ ): Statement<ParamsType, ReturnType>;
+
+ /**
+ * Is the database in a transaction?
+ *
+ * @returns `true` if the database is in a transaction, `false` otherwise
+ *
+ * @example
+ * ```ts
+ * db.run("CREATE TABLE foo (bar TEXT)");
+ * db.run("INSERT INTO foo VALUES (?)", "baz");
+ * db.run("BEGIN");
+ * db.run("INSERT INTO foo VALUES (?)", "qux");
+ * console.log(db.inTransaction());
+ * ```
+ */
+ get inTransaction(): boolean;
+
+ /**
+ * Close the database connection.
+ *
+ * It is safe to call this method multiple times. If the database is already
+ * closed, this is a no-op. Running queries after the database has been
+ * closed will throw an error.
+ *
+ * @example
+ * ```ts
+ * db.close();
+ * ```
+ * This is called automatically when the database instance is garbage collected.
+ *
+ * Internally, this calls `sqlite3_close_v2`.
+ */
+ close(): void;
+
+ /**
+ * The filename passed when `new Database()` was called
+ * @example
+ * ```ts
+ * const db = new Database("mydb.sqlite");
+ * console.log(db.filename);
+ * // => "mydb.sqlite"
+ * ```
+ */
+ readonly filename: string;
+
+ /**
+ * The underlying `sqlite3` database handle
+ *
+ * In native code, this is not a file descriptor, but an index into an array of database handles
+ */
+ readonly handle: number;
+
+ /**
+ * Load a SQLite3 extension
+ *
+ * macOS requires a custom SQLite3 library to be linked because the Apple build of SQLite for macOS disables loading extensions. See {@link Database.setCustomSQLite}
+ *
+ * Bun chooses the Apple build of SQLite on macOS because it brings a ~50% performance improvement.
+ *
+ * @param extension name/path of the extension to load
+ * @param entryPoint optional entry point of the extension
+ */
+ loadExtension(extension, entryPoint?: string): void;
+
+ /**
+ * Change the dynamic library path to SQLite
+ *
+ * @note macOS-only
+ *
+ * This only works before SQLite is loaded, so
+ * that's before you call `new Database()`.
+ *
+ * It can only be run once because this will load
+ * the SQLite library into the process.
+ *
+ * @param path The path to the SQLite library
+ *
+ */
+ static setCustomSQLite(path: string): boolean;
+
+ /**
+ * Creates a function that always runs inside a transaction. When the
+ * function is invoked, it will begin a new transaction. When the function
+ * returns, the transaction will be committed. If an exception is thrown,
+ * the transaction will be rolled back (and the exception will propagate as
+ * usual).
+ *
+ * @param insideTransaction The callback which runs inside a transaction
+ *
+ * @example
+ * ```ts
+ * // setup
+ * import { Database } from "bun:sqlite";
+ * const db = Database.open(":memory:");
+ * db.exec(
+ * "CREATE TABLE cats (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT UNIQUE, age INTEGER)"
+ * );
+ *
+ * const insert = db.prepare("INSERT INTO cats (name, age) VALUES ($name, $age)");
+ * const insertMany = db.transaction((cats) => {
+ * for (const cat of cats) insert.run(cat);
+ * });
+ *
+ * insertMany([
+ * { $name: "Joey", $age: 2 },
+ * { $name: "Sally", $age: 4 },
+ * { $name: "Junior", $age: 1 },
+ * ]);
+ * ```
+ */
+ transaction(insideTransaction: (...args: any) => void): CallableFunction & {
+ /**
+ * uses "BEGIN DEFERRED"
+ */
+ deferred: (...args: any) => void;
+ /**
+ * uses "BEGIN IMMEDIATE"
+ */
+ immediate: (...args: any) => void;
+ /**
+ * uses "BEGIN EXCLUSIVE"
+ */
+ exclusive: (...args: any) => void;
+ };
+ }
+
+ export { default as Database };
+
+ /**
+ * A prepared statement.
+ *
+ * This is returned by {@link Database.prepare} and {@link Database.query}.
+ *
+ * @example
+ * ```ts
+ * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
+ * stmt.all("baz");
+ * // => [{bar: "baz"}]
+ * ```
+ *
+ * @example
+ * ```ts
+ * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
+ * stmt.get("baz");
+ * // => {bar: "baz"}
+ * ```
+ *
+ * @example
+ * ```ts
+ * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
+ * stmt.run("baz");
+ * // => undefined
+ * ```
+ */
+ export class Statement<ParamsType = SQLQueryBindings, ReturnType = any> {
+ /**
+ * Creates a new prepared statement from native code.
+ *
+ * This is used internally by the {@link Database} class. Probably you don't need to call this yourself.
+ */
+ constructor(nativeHandle: any);
+
+ /**
+ * Execute the prepared statement and return all results as objects.
+ *
+ * @param params optional values to bind to the statement. If omitted, the statement is run with the last bound values or no parameters if there are none.
+ *
+ * @example
+ * ```ts
+ * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
+ *
+ * stmt.all("baz");
+ * // => [{bar: "baz"}]
+ *
+ * stmt.all();
+ * // => [{bar: "baz"}]
+ *
+ * stmt.all("foo");
+ * // => [{bar: "foo"}]
+ * ```
+ */
+ all(...params: ParamsType[]): ReturnType[];
+
+ /**
+ * Execute the prepared statement and return **the first** result.
+ *
+ * If no result is returned, this returns `null`.
+ *
+ * @param params optional values to bind to the statement. If omitted, the statement is run with the last bound values or no parameters if there are none.
+ *
+ * @example
+ * ```ts
+ * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
+ *
+ * stmt.all("baz");
+ * // => [{bar: "baz"}]
+ *
+ * stmt.all();
+ * // => [{bar: "baz"}]
+ *
+ * stmt.all("foo");
+ * // => [{bar: "foo"}]
+ * ```
+ *
+ * The following types can be used when binding parameters:
+ *
+ * | JavaScript type | SQLite type |
+ * | -------------- | ----------- |
+ * | `string` | `TEXT` |
+ * | `number` | `INTEGER` or `DECIMAL` |
+ * | `boolean` | `INTEGER` (1 or 0) |
+ * | `Uint8Array` | `BLOB` |
+ * | `Buffer` | `BLOB` |
+ * | `bigint` | `INTEGER` |
+ * | `null` | `NULL` |
+ *
+ */
+ get(...params: ParamsType[]): ReturnType | null;
+
+ /**
+ * Execute the prepared statement. This returns `undefined`.
+ *
+ * @param params optional values to bind to the statement. If omitted, the statement is run with the last bound values or no parameters if there are none.
+ *
+ * @example
+ * ```ts
+ * const stmt = db.prepare("UPDATE foo SET bar = ?");
+ * stmt.run("baz");
+ * // => undefined
+ *
+ * stmt.run();
+ * // => undefined
+ *
+ * stmt.run("foo");
+ * // => undefined
+ * ```
+ *
+ * The following types can be used when binding parameters:
+ *
+ * | JavaScript type | SQLite type |
+ * | -------------- | ----------- |
+ * | `string` | `TEXT` |
+ * | `number` | `INTEGER` or `DECIMAL` |
+ * | `boolean` | `INTEGER` (1 or 0) |
+ * | `Uint8Array` | `BLOB` |
+ * | `Buffer` | `BLOB` |
+ * | `bigint` | `INTEGER` |
+ * | `null` | `NULL` |
+ *
+ */
+ run(...params: ParamsType): void;
+
+ /**
+ * Execute the prepared statement and return the results as an array of arrays.
+ *
+ * This is a little faster than {@link all}.
+ *
+ * @param params optional values to bind to the statement. If omitted, the statement is run with the last bound values or no parameters if there are none.
+ *
+ * @example
+ * ```ts
+ * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
+ *
+ * stmt.values("baz");
+ * // => [['baz']]
+ *
+ * stmt.values();
+ * // => [['baz']]
+ *
+ * stmt.values("foo");
+ * // => [['foo']]
+ * ```
+ *
+ * The following types can be used when binding parameters:
+ *
+ * | JavaScript type | SQLite type |
+ * | -------------- | ----------- |
+ * | `string` | `TEXT` |
+ * | `number` | `INTEGER` or `DECIMAL` |
+ * | `boolean` | `INTEGER` (1 or 0) |
+ * | `Uint8Array` | `BLOB` |
+ * | `Buffer` | `BLOB` |
+ * | `bigint` | `INTEGER` |
+ * | `null` | `NULL` |
+ *
+ */
+ values(
+ ...params: ParamsType
+ ): Array<Array<string | bigint | number | boolean | Uint8Array>>;
+
+ /**
+ * The names of the columns returned by the prepared statement.
+ * @example
+ * ```ts
+ * const stmt = db.prepare("SELECT bar FROM foo WHERE bar = ?");
+ *
+ * console.log(stmt.columnNames);
+ * // => ["bar"]
+ * ```
+ */
+ readonly columnNames: string[];
+
+ /**
+ * The number of parameters expected in the prepared statement.
+ * @example
+ * ```ts
+ * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
+ * console.log(stmt.paramsCount);
+ * // => 1
+ * ```
+ * @example
+ * ```ts
+ * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ? AND baz = ?");
+ * console.log(stmt.paramsCount);
+ * // => 2
+ * ```
+ *
+ */
+ readonly paramsCount: number;
+
+ /**
+ * Finalize the prepared statement, freeing the resources used by the
+ * statement and preventing it from being executed again.
+ *
+ * This is called automatically when the prepared statement is garbage collected.
+ *
+ * It is safe to call this multiple times. Calling this on a finalized
+ * statement has no effect.
+ *
+ * Internally, this calls `sqlite3_finalize`.
+ */
+ finalize(): void;
+
+ /**
+ * Return the expanded SQL string for the prepared statement.
+ *
+ * Internally, this calls `sqlite3_expanded_sql()` on the underlying `sqlite3_stmt`.
+ *
+ * @example
+ * ```ts
+ * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?", "baz");
+ * console.log(stmt.toString());
+ * // => "SELECT * FROM foo WHERE bar = 'baz'"
+ * console.log(stmt);
+ * // => "SELECT * FROM foo WHERE bar = 'baz'"
+ * ```
+ */
+ toString(): string;
+
+ /**
+ * Native object representing the underlying `sqlite3_stmt`
+ *
+ * This is left untyped because the ABI of the native bindings may change at any time.
+ */
+ readonly native: any;
+ }
+
+ /**
+ * Constants from `sqlite3.h`
+ *
+ * This list isn't exhaustive, but some of the ones which are relevant
+ */
+ export const constants: {
+ /**
+ * Open the database as read-only (no write operations, no create).
+ * @value 0x00000001
+ */
+ SQLITE_OPEN_READONLY: number;
+ /**
+ * Open the database for reading and writing
+ * @value 0x00000002
+ */
+ SQLITE_OPEN_READWRITE: number;
+ /**
+ * Allow creating a new database
+ * @value 0x00000004
+ */
+ SQLITE_OPEN_CREATE: number;
+ /**
+ *
+ * @value 0x00000008
+ */
+ SQLITE_OPEN_DELETEONCLOSE: number;
+ /**
+ *
+ * @value 0x00000010
+ */
+ SQLITE_OPEN_EXCLUSIVE: number;
+ /**
+ *
+ * @value 0x00000020
+ */
+ SQLITE_OPEN_AUTOPROXY: number;
+ /**
+ *
+ * @value 0x00000040
+ */
+ SQLITE_OPEN_URI: number;
+ /**
+ *
+ * @value 0x00000080
+ */
+ SQLITE_OPEN_MEMORY: number;
+ /**
+ *
+ * @value 0x00000100
+ */
+ SQLITE_OPEN_MAIN_DB: number;
+ /**
+ *
+ * @value 0x00000200
+ */
+ SQLITE_OPEN_TEMP_DB: number;
+ /**
+ *
+ * @value 0x00000400
+ */
+ SQLITE_OPEN_TRANSIENT_DB: number;
+ /**
+ *
+ * @value 0x00000800
+ */
+ SQLITE_OPEN_MAIN_JOURNAL: number;
+ /**
+ *
+ * @value 0x00001000
+ */
+ SQLITE_OPEN_TEMP_JOURNAL: number;
+ /**
+ *
+ * @value 0x00002000
+ */
+ SQLITE_OPEN_SUBJOURNAL: number;
+ /**
+ *
+ * @value 0x00004000
+ */
+ SQLITE_OPEN_SUPER_JOURNAL: number;
+ /**
+ *
+ * @value 0x00008000
+ */
+ SQLITE_OPEN_NOMUTEX: number;
+ /**
+ *
+ * @value 0x00010000
+ */
+ SQLITE_OPEN_FULLMUTEX: number;
+ /**
+ *
+ * @value 0x00020000
+ */
+ SQLITE_OPEN_SHAREDCACHE: number;
+ /**
+ *
+ * @value 0x00040000
+ */
+ SQLITE_OPEN_PRIVATECACHE: number;
+ /**
+ *
+ * @value 0x00080000
+ */
+ SQLITE_OPEN_WAL: number;
+ /**
+ *
+ * @value 0x01000000
+ */
+ SQLITE_OPEN_NOFOLLOW: number;
+ /**
+ *
+ * @value 0x02000000
+ */
+ SQLITE_OPEN_EXRESCODE: number;
+ /**
+ *
+ * @value 0x01
+ */
+ SQLITE_PREPARE_PERSISTENT: number;
+ /**
+ *
+ * @value 0x02
+ */
+ SQLITE_PREPARE_NORMALIZE: number;
+ /**
+ *
+ * @value 0x04
+ */
+ SQLITE_PREPARE_NO_VTAB: number;
+ };
+
+ /**
+ * The native module implementing the sqlite3 C bindings
+ *
+ * It is lazily-initialized, so this will return `undefined` until the first
+ * call to new Database().
+ *
+ * The native module makes no gurantees about ABI stability, so it is left
+ * untyped
+ *
+ * If you need to use it directly for some reason, please let us know because
+ * that probably points to a deficiency in this API.
+ *
+ */
+ export var native: any;
+
+ export type SQLQueryBindings =
+ | string
+ | bigint
+ | TypedArray
+ | number
+ | boolean
+ | null
+ | Record<string, string | bigint | TypedArray | number | boolean | null>;
+}
+
+
// ./fs.d.ts
/**
diff --git a/types/bun/sqlite.d.ts b/types/bun/sqlite.d.ts
index f75c1e4d2..1c415f43e 100644
--- a/types/bun/sqlite.d.ts
+++ b/types/bun/sqlite.d.ts
@@ -229,7 +229,7 @@ declare module "bun:sqlite" {
*/
prepare<ParamsType = SQLQueryBindings, ReturnType = any>(
sql: string,
- ...params: ParamsType
+ ...params: ParamsType[]
): Statement<ParamsType, ReturnType>;
/**
@@ -246,7 +246,7 @@ declare module "bun:sqlite" {
* console.log(db.inTransaction());
* ```
*/
- get inTransaction(): bool;
+ get inTransaction(): boolean;
/**
* Close the database connection.
@@ -309,7 +309,7 @@ declare module "bun:sqlite" {
* @param path The path to the SQLite library
*
*/
- static setCustomSQLite(path: string): bool;
+ static setCustomSQLite(path: string): boolean;
/**
* Creates a function that always runs inside a transaction. When the
@@ -412,7 +412,7 @@ declare module "bun:sqlite" {
* // => [{bar: "foo"}]
* ```
*/
- all(...params: ParamsType): ReturnType[];
+ all(...params: ParamsType[]): ReturnType[];
/**
* Execute the prepared statement and return **the first** result.
@@ -448,7 +448,7 @@ declare module "bun:sqlite" {
* | `null` | `NULL` |
*
*/
- get(...params: ParamsType): ReturnType | null;
+ get(...params: ParamsType[]): ReturnType | null;
/**
* Execute the prepared statement. This returns `undefined`.
@@ -734,7 +734,7 @@ declare module "bun:sqlite" {
* that probably points to a deficiency in this API.
*
*/
- export const native: ?any;
+ export var native: any;
export type SQLQueryBindings =
| string