Skip to main content

Crate postgres_to_polars

Crate postgres_to_polars 

Source
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§

DataFrameBuilder
Columnar builder that accumulates rows and produces a DataFrame.
HasDataFrameBuilder
Trait implemented by structs deriving IntoDataFrame.
StreamToDataFrame
Extension trait on sqlx streams to convert query results into a Polars DataFrame.
VecToColumn
Converts a Vec<T> into a Polars Column.

Derive Macros§

IntoDataFrame
Derive macro that generates a columnar builder for converting rows into a Polars DataFrame.