| Crates.io | qail-pg |
| lib.rs | qail-pg |
| version | 0.14.22 |
| created_at | 2025-12-26 11:16:43.800376+00 |
| updated_at | 2026-01-10 13:48:42.048758+00 |
| description | Fastest async PostgreSQL driver - AST to wire protocol, optional io_uring on Linux |
| homepage | |
| repository | https://github.com/qail-io/qail |
| max_upload_size | |
| id | 2005591 |
| size | 773,190 |
PostgreSQL driver for QAIL - native wire protocol
A high-performance PostgreSQL driver that speaks the wire protocol directly. No SQL strings, no SQL injection - just pure AST-to-wire encoding.
pipeline_batch()tokio-rustlsPgPoolbegin/commit/rollback support[!CAUTION] Alpha Software: QAIL is currently in alpha. While we strive for stability, the API is evolving to ensure it remains ergonomic and truly AST-native. Do not use in production environments yet.
[dependencies]
qail-pg = "0.13.1"
qail-core = "0.13.1"
use qail_core::ast::{QailCmd, builders::*};
use qail_pg::PgDriver;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Connect with password
let mut driver = PgDriver::connect_with_password(
"localhost", 5432, "postgres", "mydb", "password"
).await?;
// Build a query using QAIL AST
let cmd = QailCmd::get("users")
.columns([col("id"), col("name"), col("email")])
.filter(eq("active", true))
.order_by([("created_at", Desc)])
.limit(10);
// Execute and fetch rows
let rows = driver.fetch_all(&cmd).await?;
for row in rows {
let name: String = row.get("name");
println!("User: {}", name);
}
Ok(())
}
// Execute 10,000 queries in a single network round-trip
let cmds: Vec<QailCmd> = (0..10_000)
.map(|i| QailCmd::add("events")
.columns(["user_id", "event_type"])
.values([Value::Int(i), Value::String("login".to_string())])
).collect();
let count = driver.pipeline_batch(&cmds).await?;
println!("Inserted {} rows", count);
use qail_pg::protocol::CopyEncoder;
// Build COPY data
let mut encoder = CopyEncoder::new();
for i in 0..1_000_000 {
encoder.begin_row();
encoder.write_i64(i);
encoder.write_str(&format!("user_{}", i));
encoder.end_row();
}
// Execute COPY
driver.copy_bulk_bytes("users", &["id", "name"], encoder.finish()).await?;
use qail_pg::PgPool;
// Create a pool with 10 connections
let pool = PgPool::new(
"localhost", 5432, "postgres", "mydb", Some("password"), 10
).await?;
// Acquire a connection
let mut conn = pool.acquire().await?;
let rows = conn.fetch_all(&cmd).await?;
qail-pg uses tokio-rustls for TLS connections:
// SSL is auto-negotiated during connection
let driver = PgDriver::connect_with_password(
"pg.example.com", 5432, "user", "db", "pass"
).await?;
qail-pg works seamlessly with qail-core's ergonomic builders:
use qail_core::ast::builders::*;
// COUNT(*) FILTER (WHERE condition)
count_filter(vec![eq("status", "active")]).alias("active_count")
// NOW() - INTERVAL '24 hours'
now_minus("24 hours")
// CASE WHEN ... ELSE ... END
case_when(gt("score", 80), text("pass"))
.otherwise(text("fail"))
.alias("result")
// Type casting
cast(col("amount"), "float8")
| PostgreSQL Type | Rust Type |
|---|---|
text, varchar |
String |
int4, int8 |
i32, i64 |
float8 |
f64 |
bool |
bool |
uuid |
uuid::Uuid |
jsonb |
serde_json::Value |
timestamp |
chrono::DateTime<Utc> |
date |
chrono::NaiveDate |
numeric |
rust_decimal::Decimal |
MIT
We welcome issue reports on GitHub! Please provide detailed descriptions to help us reproduce and fix the problem. We aim to address critical issues within 1-5 business days.