Skip to content

Updated README #264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 6, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,30 +389,23 @@ await sql`
Use cursors if you need to throttle the amount of rows being returned from a query. New results won't be requested until the promise / async callback function has resolved.

```js

await sql`
select * from generate_series(1,4) as x
`.cursor(async ([row]) => {
for await (const row of sql`select * from generate_series(1,4) as x`.cursor()) {
// row = { x: 1 }
await http.request('https://example.com/wat', { row })
})
}

// All rows iterated
```

A single row will be returned by default, but you can also request batches by setting the number of rows desired in each batch as the first argument. That is useful if you can do work with the rows in parallel like in this example:
A single row will be returned by default, but you can also request batches by setting the number of rows desired in each batch as an argument of `.cursor`:

```js

await sql`
select * from generate_series(1,1000) as x
`.cursor(10, async rows => {
for await (const rows of sql`select * from generate_series(1,1000) as x`.cursor(10)) {
// rows = [{ x: 1 }, { x: 2 }, ... ]
await Promise.all(rows.map(row =>
http.request('https://example.com/wat', { row })
))
})

}
```

If an error is thrown inside the callback function no more rows will be requested and the promise will reject with the thrown error.
Expand Down