#postgresql #cursor #sql

postgres-cursor

PostgreSQL的游标抽象

5个版本 (3个破坏性更新)

使用旧的Rust 2015

0.4.0 2021年12月6日
0.3.0 2017年12月24日
0.2.2 2017年8月19日
0.2.1 2017年7月31日
0.1.0 2017年6月29日

#1024数据库接口

Download history 14/week @ 2024-03-11 20/week @ 2024-03-18 40/week @ 2024-04-01 22/week @ 2024-04-08 3/week @ 2024-04-15 1/week @ 2024-04-22 3/week @ 2024-04-29 6/week @ 2024-05-06 50/week @ 2024-05-13 36/week @ 2024-05-20 7/week @ 2024-05-27 6/week @ 2024-06-03 57/week @ 2024-06-10 24/week @ 2024-06-17 8/week @ 2024-06-24

每月95 次下载

MIT 许可证

15KB
275

rust-postgres-cursor

用于PostgreSQL的游标类型。

示例

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<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);
    }
}

依赖

~7–16MB
~231K SLoC