#postgresql #cursor #sql #sql-query

postgres-cursor

Cursor abstraction for PostgreSQL

5 releases (3 breaking)

Uses old Rust 2015

0.4.0 Dec 6, 2021
0.3.0 Dec 24, 2017
0.2.2 Aug 19, 2017
0.2.1 Jul 31, 2017
0.1.0 Jun 29, 2017

#1677 in Database interfaces

Download history 16/week @ 2024-07-21 32/week @ 2024-07-28 23/week @ 2024-08-04 21/week @ 2024-08-11 10/week @ 2024-08-18 18/week @ 2024-08-25 3/week @ 2024-09-01 2/week @ 2024-09-08 8/week @ 2024-09-15 65/week @ 2024-09-22 67/week @ 2024-09-29 15/week @ 2024-10-06 11/week @ 2024-10-13 16/week @ 2024-10-20 48/week @ 2024-10-27 1/week @ 2024-11-03

77 downloads per month

MIT license

15KB
275 lines

rust-postgres-cursor

A cursor type for use with PostgreSQL.

Example

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://jwilm@127.0.0.1/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<Vec<Row>, 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);
    }
}

Dependencies

~7–16MB
~224K SLoC