Crate postgres_cursor [] [src]

Provides a Cursor abstraction for use with the postgres crate.


extern crate postgres;
extern crate postgres_cursor;

use postgres::{Connection, TlsMode};
use postgres_cursor::Cursor;

// First, establish a connection with postgres
let conn = Connection::connect("postgres://jwilm@", TlsMode::None)

// Build the cursor
let mut cursor = Cursor::build(&conn)
    // Batch size determines rows returned in each FETCH call
    // Query is the statement to build a cursor for
    .query("SELECT id FROM products")
    // Finalize turns this builder into a cursor
    .expect("cursor creation succeeded");

// Iterate over batches of rows
for result in &mut cursor {
    // Each item returned from the iterator is a Result<Rows>.
    // 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);



Builds a Cursor


Represents a PostgreSQL cursor.


Iterator returning Rows for every call to next().