Expand description
Stream PostgreSQL query results directly into Polars DataFrames.
This crate provides a #[derive(IntoDataFrame)] macro and a .to_dataframe() extension trait
that work with sqlx streams to build DataFrames efficiently via streaming.
§Example
ⓘ
use sqlx::PgPool;
use postgres_to_polars::{IntoDataFrame, StreamToDataFrame};
#[derive(sqlx::FromRow, IntoDataFrame)]
struct User {
id: i32,
name: Option<String>,
}
let pool = PgPool::connect("postgres://localhost/db").await.unwrap();
let df = sqlx::query_as!(User, "SELECT id, name FROM users")
.fetch(&pool)
.to_dataframe(10_000) // pre-allocate for ~10K rows
.await?;Enums§
- Error
- Error type wrapping both sqlx and Polars errors.
Traits§
- Data
Frame Builder - Columnar builder that accumulates rows and produces a DataFrame.
- HasData
Frame Builder - Trait implemented by structs deriving
IntoDataFrame. - Stream
ToData Frame - Extension trait on sqlx streams to convert query results into a Polars DataFrame.
- VecTo
Column - Converts a
Vec<T>into a PolarsColumn.
Derive Macros§
- Into
Data Frame - Derive macro that generates a columnar builder for converting rows into a Polars DataFrame.