bun-types 0.0.79 → 0.0.83

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/types.d.ts +902 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bun-types",
3
- "version": "0.0.79",
3
+ "version": "0.0.83",
4
4
  "description": "Type definitions for bun.js",
5
5
  "types": "types.d.ts",
6
6
  "files": [
package/types.d.ts CHANGED
@@ -365,7 +365,7 @@ declare module "bun" {
365
365
  * const query = UserQuery;
366
366
  * ```
367
367
  */
368
- macros: MacroMap;
368
+ macros?: MacroMap;
369
369
  }
370
370
 
371
371
  /**
@@ -403,7 +403,27 @@ declare module "bun" {
403
403
  * @param code The code to transpile
404
404
  *
405
405
  */
406
- transformSync(code: StringOrBuffer, loader?: JavaScriptLoader): string;
406
+ transformSync(
407
+ code: StringOrBuffer,
408
+ loader: JavaScriptLoader,
409
+ ctx: object
410
+ ): string;
411
+ /**
412
+ * Transpile code from TypeScript or JSX into valid JavaScript.
413
+ * This function does not resolve imports.
414
+ * @param code The code to transpile
415
+ * @param ctx An object to pass to macros
416
+ *
417
+ */
418
+ transformSync(code: StringOrBuffer, ctx: object): string;
419
+
420
+ /**
421
+ * Transpile code from TypeScript or JSX into valid JavaScript.
422
+ * This function does not resolve imports.
423
+ * @param code The code to transpile
424
+ *
425
+ */
426
+ transformSync(code: StringOrBuffer, loader: JavaScriptLoader): string;
407
427
 
408
428
  /**
409
429
  * Get a list of import paths and paths from a TypeScript, JSX, TSX, or JavaScript file.
@@ -1472,6 +1492,17 @@ declare module "bun:ffi" {
1472
1492
  * ```
1473
1493
  */
1474
1494
  returns?: FFITypeOrString;
1495
+
1496
+ /**
1497
+ * Function pointer to the native function
1498
+ *
1499
+ * If provided, instead of using dlsym() to lookup the function, Bun will use this instead.
1500
+ * This pointer should not be null (0).
1501
+ *
1502
+ * This is useful if the library has already been loaded
1503
+ * or if the module is also using Node-API.
1504
+ */
1505
+ ptr?: number | bigint;
1475
1506
  }
1476
1507
 
1477
1508
  type Symbols = Record<string, FFIFunction>;
@@ -1505,7 +1536,124 @@ declare module "bun:ffi" {
1505
1536
  close(): void;
1506
1537
  }
1507
1538
 
1508
- export function dlopen(libraryName: string, symbols: Symbols): Library;
1539
+ /**
1540
+ * Open a library using `"bun:ffi"`
1541
+ *
1542
+ * @param name The name of the library or file path. This will be passed to `dlopen()`
1543
+ * @param symbols Map of symbols to load where the key is the symbol name and the value is the {@link FFIFunction}
1544
+ *
1545
+ * @example
1546
+ *
1547
+ * ```js
1548
+ * import {dlopen} from 'bun:ffi';
1549
+ *
1550
+ * const lib = dlopen("duckdb.dylib", {
1551
+ * get_version: {
1552
+ * returns: "cstring",
1553
+ * args: [],
1554
+ * },
1555
+ * });
1556
+ * lib.symbols.get_version();
1557
+ * // "1.0.0"
1558
+ * ```
1559
+ *
1560
+ * This is powered by just-in-time compiling C wrappers
1561
+ * that convert JavaScript types to C types and back. Internally,
1562
+ * bun uses [tinycc](https://github.com/TinyCC/tinycc), so a big thanks
1563
+ * goes to Fabrice Bellard and TinyCC maintainers for making this possible.
1564
+ *
1565
+ */
1566
+ export function dlopen(name: string, symbols: Symbols): Library;
1567
+
1568
+ /**
1569
+ * Turn a native library's function pointer into a JavaScript function
1570
+ *
1571
+ * Libraries using Node-API & bun:ffi in the same module could use this to skip an extra dlopen() step.
1572
+ *
1573
+ * @param fn {@link FFIFunction} declaration. `ptr` is required
1574
+ *
1575
+ * @example
1576
+ *
1577
+ * ```js
1578
+ * import {CFunction} from 'bun:ffi';
1579
+ *
1580
+ * const getVersion = new CFunction({
1581
+ * returns: "cstring",
1582
+ * args: [],
1583
+ * ptr: myNativeLibraryGetVersion,
1584
+ * });
1585
+ * getVersion();
1586
+ * getVersion.close();
1587
+ * ```
1588
+ *
1589
+ * This is powered by just-in-time compiling C wrappers
1590
+ * that convert JavaScript types to C types and back. Internally,
1591
+ * bun uses [tinycc](https://github.com/TinyCC/tinycc), so a big thanks
1592
+ * goes to Fabrice Bellard and TinyCC maintainers for making this possible.
1593
+ *
1594
+ */
1595
+ export function CFunction(
1596
+ fn: FFIFunction & { ptr: number | bigint }
1597
+ ): CallableFunction & {
1598
+ /**
1599
+ * Free the memory allocated by the wrapping function
1600
+ */
1601
+ close(): void;
1602
+ };
1603
+
1604
+ /**
1605
+ * Link a map of symbols to JavaScript functions
1606
+ *
1607
+ * This lets you use native libraries that were already loaded somehow. You usually will want {@link dlopen} instead.
1608
+ *
1609
+ * You could use this with Node-API to skip loading a second time.
1610
+ *
1611
+ * @param symbols Map of symbols to load where the key is the symbol name and the value is the {@link FFIFunction}
1612
+ *
1613
+ * @example
1614
+ *
1615
+ * ```js
1616
+ * import { linkSymbols } from "bun:ffi";
1617
+ *
1618
+ * const [majorPtr, minorPtr, patchPtr] = getVersionPtrs();
1619
+ *
1620
+ * const lib = linkSymbols({
1621
+ * // Unlike with dlopen(), the names here can be whatever you want
1622
+ * getMajor: {
1623
+ * returns: "cstring",
1624
+ * args: [],
1625
+ *
1626
+ * // Since this doesn't use dlsym(), you have to provide a valid ptr
1627
+ * // That ptr could be a number or a bigint
1628
+ * // An invalid pointer will crash your program.
1629
+ * ptr: majorPtr,
1630
+ * },
1631
+ * getMinor: {
1632
+ * returns: "cstring",
1633
+ * args: [],
1634
+ * ptr: minorPtr,
1635
+ * },
1636
+ * getPatch: {
1637
+ * returns: "cstring",
1638
+ * args: [],
1639
+ * ptr: patchPtr,
1640
+ * },
1641
+ * });
1642
+ *
1643
+ * const [major, minor, patch] = [
1644
+ * lib.symbols.getMajor(),
1645
+ * lib.symbols.getMinor(),
1646
+ * lib.symbols.getPatch(),
1647
+ * ];
1648
+ * ```
1649
+ *
1650
+ * This is powered by just-in-time compiling C wrappers
1651
+ * that convert JavaScript types to C types and back. Internally,
1652
+ * bun uses [tinycc](https://github.com/TinyCC/tinycc), so a big thanks
1653
+ * goes to Fabrice Bellard and TinyCC maintainers for making this possible.
1654
+ *
1655
+ */
1656
+ export function linkSymbols(symbols: Symbols): Library;
1509
1657
 
1510
1658
  /**
1511
1659
  * Read a pointer as a {@link Buffer}
@@ -1680,6 +1828,757 @@ declare module "bun:ffi" {
1680
1828
  }
1681
1829
 
1682
1830
 
1831
+ // ./sqlite.d.ts
1832
+
1833
+ /**
1834
+ * Fast SQLite3 driver for Bun.js
1835
+ * @since v0.0.83
1836
+ *
1837
+ * @example
1838
+ * ```ts
1839
+ * import { Database } from 'bun:sqlite';
1840
+ *
1841
+ * var db = new Database('app.db');
1842
+ * db.query('SELECT * FROM users WHERE name = ?').all('John');
1843
+ * // => [{ id: 1, name: 'John' }]
1844
+ * ```
1845
+ *
1846
+ * The following types can be used when binding parameters:
1847
+ *
1848
+ * | JavaScript type | SQLite type |
1849
+ * | -------------- | ----------- |
1850
+ * | `string` | `TEXT` |
1851
+ * | `number` | `INTEGER` or `DECIMAL` |
1852
+ * | `boolean` | `INTEGER` (1 or 0) |
1853
+ * | `Uint8Array` | `BLOB` |
1854
+ * | `Buffer` | `BLOB` |
1855
+ * | `bigint` | `INTEGER` |
1856
+ * | `null` | `NULL` |
1857
+ */
1858
+ declare module "bun:sqlite" {
1859
+ export class Database {
1860
+ /**
1861
+ * Open or create a SQLite3 database
1862
+ *
1863
+ * @param filename The filename of the database to open. Pass an empty string (`""`) or `":memory:"` for an in-memory database.
1864
+ * @param options defaults to `{readwrite: true, create: true}`. If a number, then it's treated as `SQLITE_OPEN_*` constant flags.
1865
+ *
1866
+ * @example
1867
+ *
1868
+ * ```ts
1869
+ * const db = new Database("mydb.sqlite");
1870
+ * db.run("CREATE TABLE foo (bar TEXT)");
1871
+ * db.run("INSERT INTO foo VALUES (?)", "baz");
1872
+ * console.log(db.query("SELECT * FROM foo").all());
1873
+ * ```
1874
+ *
1875
+ * @example
1876
+ *
1877
+ * Open an in-memory database
1878
+ *
1879
+ * ```ts
1880
+ * const db = new Database(":memory:");
1881
+ * db.run("CREATE TABLE foo (bar TEXT)");
1882
+ * db.run("INSERT INTO foo VALUES (?)", "hiiiiii");
1883
+ * console.log(db.query("SELECT * FROM foo").all());
1884
+ * ```
1885
+ *
1886
+ * @example
1887
+ *
1888
+ * Open read-only
1889
+ *
1890
+ * ```ts
1891
+ * const db = new Database("mydb.sqlite", {readonly: true});
1892
+ * ```
1893
+ */
1894
+ constructor(
1895
+ filename: string,
1896
+ options?:
1897
+ | number
1898
+ | {
1899
+ /**
1900
+ * Open the database as read-only (no write operations, no create).
1901
+ *
1902
+ * Equivalent to {@link constants.SQLITE_OPEN_READONLY}
1903
+ */
1904
+ readonly?: boolean;
1905
+ /**
1906
+ * Allow creating a new database
1907
+ *
1908
+ * Equivalent to {@link constants.SQLITE_OPEN_CREATE}
1909
+ */
1910
+ create?: boolean;
1911
+ /**
1912
+ * Open the database as read-write
1913
+ *
1914
+ * Equivalent to {@link constants.SQLITE_OPEN_READWRITE}
1915
+ */
1916
+ readwrite?: boolean;
1917
+ }
1918
+ );
1919
+
1920
+ /**
1921
+ * This is an alias of `new Database()`
1922
+ *
1923
+ * See {@link Database}
1924
+ */
1925
+ static open(
1926
+ filename: string,
1927
+ options?:
1928
+ | number
1929
+ | {
1930
+ /**
1931
+ * Open the database as read-only (no write operations, no create).
1932
+ *
1933
+ * Equivalent to {@link constants.SQLITE_OPEN_READONLY}
1934
+ */
1935
+ readonly?: boolean;
1936
+ /**
1937
+ * Allow creating a new database
1938
+ *
1939
+ * Equivalent to {@link constants.SQLITE_OPEN_CREATE}
1940
+ */
1941
+ create?: boolean;
1942
+ /**
1943
+ * Open the database as read-write
1944
+ *
1945
+ * Equivalent to {@link constants.SQLITE_OPEN_READWRITE}
1946
+ */
1947
+ readwrite?: boolean;
1948
+ }
1949
+ ): Database;
1950
+
1951
+ /**
1952
+ * Execute a SQL query **without returning any results**.
1953
+ *
1954
+ * This does not cache the query, so if you want to run a query multiple times, you should use {@link prepare} instead.
1955
+ *
1956
+ * @example
1957
+ * ```ts
1958
+ * db.run("CREATE TABLE foo (bar TEXT)");
1959
+ * db.run("INSERT INTO foo VALUES (?)", "baz");
1960
+ * ```
1961
+ *
1962
+ * Useful for queries like:
1963
+ * - `CREATE TABLE`
1964
+ * - `INSERT INTO`
1965
+ * - `UPDATE`
1966
+ * - `DELETE FROM`
1967
+ * - `DROP TABLE`
1968
+ * - `PRAGMA`
1969
+ * - `ATTACH DATABASE`
1970
+ * - `DETACH DATABASE`
1971
+ * - `REINDEX`
1972
+ * - `VACUUM`
1973
+ * - `EXPLAIN ANALYZE`
1974
+ * - `CREATE INDEX`
1975
+ * - `CREATE TRIGGER`
1976
+ * - `CREATE VIEW`
1977
+ * - `CREATE VIRTUAL TABLE`
1978
+ * - `CREATE TEMPORARY TABLE`
1979
+ *
1980
+ * @param sql The SQL query to run
1981
+ *
1982
+ * @param bindings Optional bindings for the query
1983
+ *
1984
+ * @returns `Database` instance
1985
+ *
1986
+ * Under the hood, this calls `sqlite3_prepare_v3` followed by `sqlite3_step` and `sqlite3_finalize`.
1987
+ *
1988
+ * * The following types can be used when binding parameters:
1989
+ *
1990
+ * | JavaScript type | SQLite type |
1991
+ * | -------------- | ----------- |
1992
+ * | `string` | `TEXT` |
1993
+ * | `number` | `INTEGER` or `DECIMAL` |
1994
+ * | `boolean` | `INTEGER` (1 or 0) |
1995
+ * | `Uint8Array` | `BLOB` |
1996
+ * | `Buffer` | `BLOB` |
1997
+ * | `bigint` | `INTEGER` |
1998
+ * | `null` | `NULL` |
1999
+ */
2000
+ run<ParamsType = SQLQueryBindings>(
2001
+ sqlQuery: string,
2002
+ ...bindings: ParamsType
2003
+ ): void;
2004
+ /**
2005
+ This is an alias of {@link Database.prototype.run}
2006
+ */
2007
+ exec<ParamsType = SQLQueryBindings>(
2008
+ sqlQuery: string,
2009
+ ...bindings: ParamsType
2010
+ ): void;
2011
+
2012
+ /**
2013
+ * Compile a SQL query and return a {@link Statement} object. This is the
2014
+ * same as {@link prepare} except that it caches the compiled query.
2015
+ *
2016
+ * This **does not execute** the query, but instead prepares it for later
2017
+ * execution and caches the compiled query if possible.
2018
+ *
2019
+ * @example
2020
+ * ```ts
2021
+ * // compile the query
2022
+ * const stmt = db.query("SELECT * FROM foo WHERE bar = ?");
2023
+ * // run the query
2024
+ * stmt.all("baz");
2025
+ *
2026
+ * // run the query again
2027
+ * stmt.all();
2028
+ * ```
2029
+ *
2030
+ * @param sql The SQL query to compile
2031
+ *
2032
+ * @returns `Statment` instance
2033
+ *
2034
+ * Under the hood, this calls `sqlite3_prepare_v3`.
2035
+ *
2036
+ */
2037
+ query<ParamsType = SQLQueryBindings, ReturnType = any>(
2038
+ sqlQuery: string
2039
+ ): Statement<ParamsType, ReturnType>;
2040
+
2041
+ /**
2042
+ * Compile a SQL query and return a {@link Statement} object.
2043
+ *
2044
+ * This does not cache the compiled query and does not execute the query.
2045
+ *
2046
+ * @example
2047
+ * ```ts
2048
+ * // compile the query
2049
+ * const stmt = db.query("SELECT * FROM foo WHERE bar = ?");
2050
+ * // run the query
2051
+ * stmt.all("baz");
2052
+ * ```
2053
+ *
2054
+ * @param sql The SQL query to compile
2055
+ * @param params Optional bindings for the query
2056
+ *
2057
+ * @returns `Statment` instance
2058
+ *
2059
+ * Under the hood, this calls `sqlite3_prepare_v3`.
2060
+ *
2061
+ */
2062
+ prepare<ParamsType = SQLQueryBindings, ReturnType = any>(
2063
+ sql: string,
2064
+ ...params: ParamsType[]
2065
+ ): Statement<ParamsType, ReturnType>;
2066
+
2067
+ /**
2068
+ * Is the database in a transaction?
2069
+ *
2070
+ * @returns `true` if the database is in a transaction, `false` otherwise
2071
+ *
2072
+ * @example
2073
+ * ```ts
2074
+ * db.run("CREATE TABLE foo (bar TEXT)");
2075
+ * db.run("INSERT INTO foo VALUES (?)", "baz");
2076
+ * db.run("BEGIN");
2077
+ * db.run("INSERT INTO foo VALUES (?)", "qux");
2078
+ * console.log(db.inTransaction());
2079
+ * ```
2080
+ */
2081
+ get inTransaction(): boolean;
2082
+
2083
+ /**
2084
+ * Close the database connection.
2085
+ *
2086
+ * It is safe to call this method multiple times. If the database is already
2087
+ * closed, this is a no-op. Running queries after the database has been
2088
+ * closed will throw an error.
2089
+ *
2090
+ * @example
2091
+ * ```ts
2092
+ * db.close();
2093
+ * ```
2094
+ * This is called automatically when the database instance is garbage collected.
2095
+ *
2096
+ * Internally, this calls `sqlite3_close_v2`.
2097
+ */
2098
+ close(): void;
2099
+
2100
+ /**
2101
+ * The filename passed when `new Database()` was called
2102
+ * @example
2103
+ * ```ts
2104
+ * const db = new Database("mydb.sqlite");
2105
+ * console.log(db.filename);
2106
+ * // => "mydb.sqlite"
2107
+ * ```
2108
+ */
2109
+ readonly filename: string;
2110
+
2111
+ /**
2112
+ * The underlying `sqlite3` database handle
2113
+ *
2114
+ * In native code, this is not a file descriptor, but an index into an array of database handles
2115
+ */
2116
+ readonly handle: number;
2117
+
2118
+ /**
2119
+ * Load a SQLite3 extension
2120
+ *
2121
+ * macOS requires a custom SQLite3 library to be linked because the Apple build of SQLite for macOS disables loading extensions. See {@link Database.setCustomSQLite}
2122
+ *
2123
+ * Bun chooses the Apple build of SQLite on macOS because it brings a ~50% performance improvement.
2124
+ *
2125
+ * @param extension name/path of the extension to load
2126
+ * @param entryPoint optional entry point of the extension
2127
+ */
2128
+ loadExtension(extension, entryPoint?: string): void;
2129
+
2130
+ /**
2131
+ * Change the dynamic library path to SQLite
2132
+ *
2133
+ * @note macOS-only
2134
+ *
2135
+ * This only works before SQLite is loaded, so
2136
+ * that's before you call `new Database()`.
2137
+ *
2138
+ * It can only be run once because this will load
2139
+ * the SQLite library into the process.
2140
+ *
2141
+ * @param path The path to the SQLite library
2142
+ *
2143
+ */
2144
+ static setCustomSQLite(path: string): boolean;
2145
+
2146
+ /**
2147
+ * Creates a function that always runs inside a transaction. When the
2148
+ * function is invoked, it will begin a new transaction. When the function
2149
+ * returns, the transaction will be committed. If an exception is thrown,
2150
+ * the transaction will be rolled back (and the exception will propagate as
2151
+ * usual).
2152
+ *
2153
+ * @param insideTransaction The callback which runs inside a transaction
2154
+ *
2155
+ * @example
2156
+ * ```ts
2157
+ * // setup
2158
+ * import { Database } from "bun:sqlite";
2159
+ * const db = Database.open(":memory:");
2160
+ * db.exec(
2161
+ * "CREATE TABLE cats (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT UNIQUE, age INTEGER)"
2162
+ * );
2163
+ *
2164
+ * const insert = db.prepare("INSERT INTO cats (name, age) VALUES ($name, $age)");
2165
+ * const insertMany = db.transaction((cats) => {
2166
+ * for (const cat of cats) insert.run(cat);
2167
+ * });
2168
+ *
2169
+ * insertMany([
2170
+ * { $name: "Joey", $age: 2 },
2171
+ * { $name: "Sally", $age: 4 },
2172
+ * { $name: "Junior", $age: 1 },
2173
+ * ]);
2174
+ * ```
2175
+ */
2176
+ transaction(insideTransaction: (...args: any) => void): CallableFunction & {
2177
+ /**
2178
+ * uses "BEGIN DEFERRED"
2179
+ */
2180
+ deferred: (...args: any) => void;
2181
+ /**
2182
+ * uses "BEGIN IMMEDIATE"
2183
+ */
2184
+ immediate: (...args: any) => void;
2185
+ /**
2186
+ * uses "BEGIN EXCLUSIVE"
2187
+ */
2188
+ exclusive: (...args: any) => void;
2189
+ };
2190
+ }
2191
+
2192
+ export { default as Database };
2193
+
2194
+ /**
2195
+ * A prepared statement.
2196
+ *
2197
+ * This is returned by {@link Database.prepare} and {@link Database.query}.
2198
+ *
2199
+ * @example
2200
+ * ```ts
2201
+ * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
2202
+ * stmt.all("baz");
2203
+ * // => [{bar: "baz"}]
2204
+ * ```
2205
+ *
2206
+ * @example
2207
+ * ```ts
2208
+ * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
2209
+ * stmt.get("baz");
2210
+ * // => {bar: "baz"}
2211
+ * ```
2212
+ *
2213
+ * @example
2214
+ * ```ts
2215
+ * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
2216
+ * stmt.run("baz");
2217
+ * // => undefined
2218
+ * ```
2219
+ */
2220
+ export class Statement<ParamsType = SQLQueryBindings, ReturnType = any> {
2221
+ /**
2222
+ * Creates a new prepared statement from native code.
2223
+ *
2224
+ * This is used internally by the {@link Database} class. Probably you don't need to call this yourself.
2225
+ */
2226
+ constructor(nativeHandle: any);
2227
+
2228
+ /**
2229
+ * Execute the prepared statement and return all results as objects.
2230
+ *
2231
+ * @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.
2232
+ *
2233
+ * @example
2234
+ * ```ts
2235
+ * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
2236
+ *
2237
+ * stmt.all("baz");
2238
+ * // => [{bar: "baz"}]
2239
+ *
2240
+ * stmt.all();
2241
+ * // => [{bar: "baz"}]
2242
+ *
2243
+ * stmt.all("foo");
2244
+ * // => [{bar: "foo"}]
2245
+ * ```
2246
+ */
2247
+ all(...params: ParamsType[]): ReturnType[];
2248
+
2249
+ /**
2250
+ * Execute the prepared statement and return **the first** result.
2251
+ *
2252
+ * If no result is returned, this returns `null`.
2253
+ *
2254
+ * @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.
2255
+ *
2256
+ * @example
2257
+ * ```ts
2258
+ * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
2259
+ *
2260
+ * stmt.all("baz");
2261
+ * // => [{bar: "baz"}]
2262
+ *
2263
+ * stmt.all();
2264
+ * // => [{bar: "baz"}]
2265
+ *
2266
+ * stmt.all("foo");
2267
+ * // => [{bar: "foo"}]
2268
+ * ```
2269
+ *
2270
+ * The following types can be used when binding parameters:
2271
+ *
2272
+ * | JavaScript type | SQLite type |
2273
+ * | -------------- | ----------- |
2274
+ * | `string` | `TEXT` |
2275
+ * | `number` | `INTEGER` or `DECIMAL` |
2276
+ * | `boolean` | `INTEGER` (1 or 0) |
2277
+ * | `Uint8Array` | `BLOB` |
2278
+ * | `Buffer` | `BLOB` |
2279
+ * | `bigint` | `INTEGER` |
2280
+ * | `null` | `NULL` |
2281
+ *
2282
+ */
2283
+ get(...params: ParamsType[]): ReturnType | null;
2284
+
2285
+ /**
2286
+ * Execute the prepared statement. This returns `undefined`.
2287
+ *
2288
+ * @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.
2289
+ *
2290
+ * @example
2291
+ * ```ts
2292
+ * const stmt = db.prepare("UPDATE foo SET bar = ?");
2293
+ * stmt.run("baz");
2294
+ * // => undefined
2295
+ *
2296
+ * stmt.run();
2297
+ * // => undefined
2298
+ *
2299
+ * stmt.run("foo");
2300
+ * // => undefined
2301
+ * ```
2302
+ *
2303
+ * The following types can be used when binding parameters:
2304
+ *
2305
+ * | JavaScript type | SQLite type |
2306
+ * | -------------- | ----------- |
2307
+ * | `string` | `TEXT` |
2308
+ * | `number` | `INTEGER` or `DECIMAL` |
2309
+ * | `boolean` | `INTEGER` (1 or 0) |
2310
+ * | `Uint8Array` | `BLOB` |
2311
+ * | `Buffer` | `BLOB` |
2312
+ * | `bigint` | `INTEGER` |
2313
+ * | `null` | `NULL` |
2314
+ *
2315
+ */
2316
+ run(...params: ParamsType[]): void;
2317
+
2318
+ /**
2319
+ * Execute the prepared statement and return the results as an array of arrays.
2320
+ *
2321
+ * This is a little faster than {@link all}.
2322
+ *
2323
+ * @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.
2324
+ *
2325
+ * @example
2326
+ * ```ts
2327
+ * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
2328
+ *
2329
+ * stmt.values("baz");
2330
+ * // => [['baz']]
2331
+ *
2332
+ * stmt.values();
2333
+ * // => [['baz']]
2334
+ *
2335
+ * stmt.values("foo");
2336
+ * // => [['foo']]
2337
+ * ```
2338
+ *
2339
+ * The following types can be used when binding parameters:
2340
+ *
2341
+ * | JavaScript type | SQLite type |
2342
+ * | -------------- | ----------- |
2343
+ * | `string` | `TEXT` |
2344
+ * | `number` | `INTEGER` or `DECIMAL` |
2345
+ * | `boolean` | `INTEGER` (1 or 0) |
2346
+ * | `Uint8Array` | `BLOB` |
2347
+ * | `Buffer` | `BLOB` |
2348
+ * | `bigint` | `INTEGER` |
2349
+ * | `null` | `NULL` |
2350
+ *
2351
+ */
2352
+ values(
2353
+ ...params: ParamsType[]
2354
+ ): Array<Array<string | bigint | number | boolean | Uint8Array>>;
2355
+
2356
+ /**
2357
+ * The names of the columns returned by the prepared statement.
2358
+ * @example
2359
+ * ```ts
2360
+ * const stmt = db.prepare("SELECT bar FROM foo WHERE bar = ?");
2361
+ *
2362
+ * console.log(stmt.columnNames);
2363
+ * // => ["bar"]
2364
+ * ```
2365
+ */
2366
+ readonly columnNames: string[];
2367
+
2368
+ /**
2369
+ * The number of parameters expected in the prepared statement.
2370
+ * @example
2371
+ * ```ts
2372
+ * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
2373
+ * console.log(stmt.paramsCount);
2374
+ * // => 1
2375
+ * ```
2376
+ * @example
2377
+ * ```ts
2378
+ * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ? AND baz = ?");
2379
+ * console.log(stmt.paramsCount);
2380
+ * // => 2
2381
+ * ```
2382
+ *
2383
+ */
2384
+ readonly paramsCount: number;
2385
+
2386
+ /**
2387
+ * Finalize the prepared statement, freeing the resources used by the
2388
+ * statement and preventing it from being executed again.
2389
+ *
2390
+ * This is called automatically when the prepared statement is garbage collected.
2391
+ *
2392
+ * It is safe to call this multiple times. Calling this on a finalized
2393
+ * statement has no effect.
2394
+ *
2395
+ * Internally, this calls `sqlite3_finalize`.
2396
+ */
2397
+ finalize(): void;
2398
+
2399
+ /**
2400
+ * Return the expanded SQL string for the prepared statement.
2401
+ *
2402
+ * Internally, this calls `sqlite3_expanded_sql()` on the underlying `sqlite3_stmt`.
2403
+ *
2404
+ * @example
2405
+ * ```ts
2406
+ * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?", "baz");
2407
+ * console.log(stmt.toString());
2408
+ * // => "SELECT * FROM foo WHERE bar = 'baz'"
2409
+ * console.log(stmt);
2410
+ * // => "SELECT * FROM foo WHERE bar = 'baz'"
2411
+ * ```
2412
+ */
2413
+ toString(): string;
2414
+
2415
+ /**
2416
+ * Native object representing the underlying `sqlite3_stmt`
2417
+ *
2418
+ * This is left untyped because the ABI of the native bindings may change at any time.
2419
+ */
2420
+ readonly native: any;
2421
+ }
2422
+
2423
+ /**
2424
+ * Constants from `sqlite3.h`
2425
+ *
2426
+ * This list isn't exhaustive, but some of the ones which are relevant
2427
+ */
2428
+ export const constants: {
2429
+ /**
2430
+ * Open the database as read-only (no write operations, no create).
2431
+ * @value 0x00000001
2432
+ */
2433
+ SQLITE_OPEN_READONLY: number;
2434
+ /**
2435
+ * Open the database for reading and writing
2436
+ * @value 0x00000002
2437
+ */
2438
+ SQLITE_OPEN_READWRITE: number;
2439
+ /**
2440
+ * Allow creating a new database
2441
+ * @value 0x00000004
2442
+ */
2443
+ SQLITE_OPEN_CREATE: number;
2444
+ /**
2445
+ *
2446
+ * @value 0x00000008
2447
+ */
2448
+ SQLITE_OPEN_DELETEONCLOSE: number;
2449
+ /**
2450
+ *
2451
+ * @value 0x00000010
2452
+ */
2453
+ SQLITE_OPEN_EXCLUSIVE: number;
2454
+ /**
2455
+ *
2456
+ * @value 0x00000020
2457
+ */
2458
+ SQLITE_OPEN_AUTOPROXY: number;
2459
+ /**
2460
+ *
2461
+ * @value 0x00000040
2462
+ */
2463
+ SQLITE_OPEN_URI: number;
2464
+ /**
2465
+ *
2466
+ * @value 0x00000080
2467
+ */
2468
+ SQLITE_OPEN_MEMORY: number;
2469
+ /**
2470
+ *
2471
+ * @value 0x00000100
2472
+ */
2473
+ SQLITE_OPEN_MAIN_DB: number;
2474
+ /**
2475
+ *
2476
+ * @value 0x00000200
2477
+ */
2478
+ SQLITE_OPEN_TEMP_DB: number;
2479
+ /**
2480
+ *
2481
+ * @value 0x00000400
2482
+ */
2483
+ SQLITE_OPEN_TRANSIENT_DB: number;
2484
+ /**
2485
+ *
2486
+ * @value 0x00000800
2487
+ */
2488
+ SQLITE_OPEN_MAIN_JOURNAL: number;
2489
+ /**
2490
+ *
2491
+ * @value 0x00001000
2492
+ */
2493
+ SQLITE_OPEN_TEMP_JOURNAL: number;
2494
+ /**
2495
+ *
2496
+ * @value 0x00002000
2497
+ */
2498
+ SQLITE_OPEN_SUBJOURNAL: number;
2499
+ /**
2500
+ *
2501
+ * @value 0x00004000
2502
+ */
2503
+ SQLITE_OPEN_SUPER_JOURNAL: number;
2504
+ /**
2505
+ *
2506
+ * @value 0x00008000
2507
+ */
2508
+ SQLITE_OPEN_NOMUTEX: number;
2509
+ /**
2510
+ *
2511
+ * @value 0x00010000
2512
+ */
2513
+ SQLITE_OPEN_FULLMUTEX: number;
2514
+ /**
2515
+ *
2516
+ * @value 0x00020000
2517
+ */
2518
+ SQLITE_OPEN_SHAREDCACHE: number;
2519
+ /**
2520
+ *
2521
+ * @value 0x00040000
2522
+ */
2523
+ SQLITE_OPEN_PRIVATECACHE: number;
2524
+ /**
2525
+ *
2526
+ * @value 0x00080000
2527
+ */
2528
+ SQLITE_OPEN_WAL: number;
2529
+ /**
2530
+ *
2531
+ * @value 0x01000000
2532
+ */
2533
+ SQLITE_OPEN_NOFOLLOW: number;
2534
+ /**
2535
+ *
2536
+ * @value 0x02000000
2537
+ */
2538
+ SQLITE_OPEN_EXRESCODE: number;
2539
+ /**
2540
+ *
2541
+ * @value 0x01
2542
+ */
2543
+ SQLITE_PREPARE_PERSISTENT: number;
2544
+ /**
2545
+ *
2546
+ * @value 0x02
2547
+ */
2548
+ SQLITE_PREPARE_NORMALIZE: number;
2549
+ /**
2550
+ *
2551
+ * @value 0x04
2552
+ */
2553
+ SQLITE_PREPARE_NO_VTAB: number;
2554
+ };
2555
+
2556
+ /**
2557
+ * The native module implementing the sqlite3 C bindings
2558
+ *
2559
+ * It is lazily-initialized, so this will return `undefined` until the first
2560
+ * call to new Database().
2561
+ *
2562
+ * The native module makes no gurantees about ABI stability, so it is left
2563
+ * untyped
2564
+ *
2565
+ * If you need to use it directly for some reason, please let us know because
2566
+ * that probably points to a deficiency in this API.
2567
+ *
2568
+ */
2569
+ export var native: any;
2570
+
2571
+ export type SQLQueryBindings =
2572
+ | string
2573
+ | bigint
2574
+ | TypedArray
2575
+ | number
2576
+ | boolean
2577
+ | null
2578
+ | Record<string, string | bigint | TypedArray | number | boolean | null>;
2579
+ }
2580
+
2581
+
1683
2582
  // ./fs.d.ts
1684
2583
 
1685
2584
  /**