mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
docs(sqlite): fix .run() return value documentation (#25060)
Co-authored-by: Alistair Smith <hi@alistair.sh>
This commit is contained in:
@@ -303,7 +303,7 @@ Internally, this calls [`sqlite3_reset`](https://www.sqlite.org/capi3ref.html#sq
|
||||
|
||||
### `.run()`
|
||||
|
||||
Use `.run()` to run a query and get back `undefined`. This is useful for schema-modifying queries (e.g. `CREATE TABLE`) or bulk write operations.
|
||||
Use `.run()` to run a query and get back an object with execution metadata. This is useful for schema-modifying queries (e.g. `CREATE TABLE`) or bulk write operations.
|
||||
|
||||
```ts db.ts icon="/icons/typescript.svg" highlight={2}
|
||||
const query = db.query(`create table foo;`);
|
||||
|
||||
31
packages/bun-types/sqlite.d.ts
vendored
31
packages/bun-types/sqlite.d.ts
vendored
@@ -154,12 +154,6 @@ declare module "bun:sqlite" {
|
||||
* | `bigint` | `INTEGER` |
|
||||
* | `null` | `NULL` |
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* db.run("CREATE TABLE foo (bar TEXT)");
|
||||
* db.run("INSERT INTO foo VALUES (?)", ["baz"]);
|
||||
* ```
|
||||
*
|
||||
* Useful for queries like:
|
||||
* - `CREATE TABLE`
|
||||
* - `INSERT INTO`
|
||||
@@ -180,8 +174,14 @@ declare module "bun:sqlite" {
|
||||
*
|
||||
* @param sql The SQL query to run
|
||||
* @param bindings Optional bindings for the query
|
||||
* @returns A `Changes` object with `changes` and `lastInsertRowid` properties
|
||||
*
|
||||
* @returns `Database` instance
|
||||
* @example
|
||||
* ```ts
|
||||
* db.run("CREATE TABLE foo (bar TEXT)");
|
||||
* db.run("INSERT INTO foo VALUES (?)", ["baz"]);
|
||||
* // => { changes: 1, lastInsertRowid: 1 }
|
||||
* ```
|
||||
*/
|
||||
run<ParamsType extends SQLQueryBindings[]>(sql: string, ...bindings: ParamsType[]): Changes;
|
||||
|
||||
@@ -670,18 +670,19 @@ declare module "bun:sqlite" {
|
||||
* Execute the prepared statement.
|
||||
*
|
||||
* @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.
|
||||
* @returns A `Changes` object with `changes` and `lastInsertRowid` properties
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const stmt = db.prepare("UPDATE foo SET bar = ?");
|
||||
* stmt.run("baz");
|
||||
* // => undefined
|
||||
* const insert = db.prepare("INSERT INTO users (name) VALUES (?)");
|
||||
* insert.run("Alice");
|
||||
* // => { changes: 1, lastInsertRowid: 1 }
|
||||
* insert.run("Bob");
|
||||
* // => { changes: 1, lastInsertRowid: 2 }
|
||||
*
|
||||
* stmt.run();
|
||||
* // => undefined
|
||||
*
|
||||
* stmt.run("foo");
|
||||
* // => undefined
|
||||
* const update = db.prepare("UPDATE users SET name = ? WHERE id = ?");
|
||||
* update.run("Charlie", 1);
|
||||
* // => { changes: 1, lastInsertRowid: 2 }
|
||||
* ```
|
||||
*
|
||||
* The following types can be used when binding parameters:
|
||||
|
||||
Reference in New Issue
Block a user