Skip to content

Commit

Permalink
Some types and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner committed Oct 12, 2024
1 parent 6cf9c41 commit 9ed3858
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
22 changes: 22 additions & 0 deletions docs/api/sqlite.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,28 @@ As a performance optimization, the class constructor is not called, default init

The database columns are set as properties on the class instance.

### `.iterate()` (`@@iterator`)

Use `.iterate()` to run a query and incrementally return results. This is useful for large result sets that you want to process one row at a time without loading all the results into memory.

```ts
const query = db.query("SELECT * FROM foo");
for (const row of query.iterate()) {
console.log(row);
}
```

You can also use the `@@iterator` protocol:

```ts
const query = db.query("SELECT * FROM foo");
for (const row of query) {
console.log(row);
}
```

This feature was added in Bun v1.1.31.

### `.values()`

Use `values()` to run a query and get back all results as an array of arrays.
Expand Down
9 changes: 9 additions & 0 deletions packages/bun-types/sqlite.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,15 @@ declare module "bun:sqlite" {
*/
get(...params: ParamsType): ReturnType | null;

/**
* Execute the prepared statement and return an
*
* @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.
*
*/
iterate(...params: ParamsType): IterableIterator<ReturnType>;
[Symbol.iterator](): IterableIterator<ReturnType>;

/**
* Execute the prepared statement. This returns `undefined`.
*
Expand Down

0 comments on commit 9ed3858

Please sign in to comment.