Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jwilm/rust-postgres-cursor
A Cursor type for use with rust-postgres
https://github.com/jwilm/rust-postgres-cursor
cursor postgresql rust
Last synced: 22 days ago
JSON representation
A Cursor type for use with rust-postgres
- Host: GitHub
- URL: https://github.com/jwilm/rust-postgres-cursor
- Owner: jwilm
- License: mit
- Created: 2017-06-07T05:38:39.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-05-31T05:34:04.000Z (over 1 year ago)
- Last Synced: 2024-10-05T01:27:18.066Z (about 1 month ago)
- Topics: cursor, postgresql, rust
- Language: Rust
- Size: 11.7 KB
- Stars: 12
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
rust-postgres-cursor
====================A cursor type for use with PostgreSQL.
## Example
```rust
extern crate postgres;
extern crate postgres_cursor;use postgres::{Client, NoTls};
use postgres_cursor::Cursor;// First, establish a connection with postgres
let mut client = Client::connect("postgres://[email protected]/foo", NoTls)
.expect("connect");// Build the cursor
let mut cursor = Cursor::build(&mut client)
// Batch size determines rows returned in each FETCH call
.batch_size(10)
// Query is the statement to build a cursor for
.query("SELECT id FROM products")
// Finalize turns this builder into a cursor
.finalize()
.expect("cursor creation succeeded");// Iterate over batches of rows
for result in &mut cursor {
// Each item returned from the iterator is a Result, postgres::Error>.
// This is because each call to `next()` makes a query
// to the database.
let rows = result.unwrap();// After handling errors, rows returned in this iteration
// can be iterated over.
for row in &rows {
println!("{:?}", row);
}
}
```