rust-ef-postgres 1.5.3

PostgreSQL provider for Rust Entity Framework
Documentation

lref-provider-postgres

Crates.io License: MIT

PostgreSQL database provider for Rust Entity Framework (lref).

Implements DatabaseProvider, SqlGenerator, and AsyncConnection traits for PostgreSQL using deadpool-postgres for connection pooling.


Features

  • Connection pooling via deadpool-postgres
  • PostgreSQL-native parameterized queries ($1, $2, ...)
  • Double-quoted identifier quoting ("table_name")
  • RETURNING * support for INSERT auto-increment backfill
  • SERIAL / BIGSERIAL type mapping for auto-increment columns
  • Full CRUD: execute(), query(), transactions
  • Database introspection (information_schema.columns + table_constraints)

Quick Start

[dependencies]

lref = "0.1"

lref-provider-postgres = "0.1"

tokio = { version = "1", features = ["full"] }

use lref::provider::DatabaseProvider;
use lref_provider_postgres::PostgresProvider;
use std::sync::Arc;

let provider = Arc::new(PostgresProvider::new(
    "postgres://user:password@localhost/mydb",
    5,  // pool size
)?);

// Get a connection
let mut conn = provider.get_connection().await?;

// Execute parameterized query
conn.execute("INSERT INTO blogs (url, rating) VALUES ($1, $2)", &[
    DbValue::String("https://example.com".into()),
    DbValue::I32(5),
]).await?;

// Query rows
let rows = conn.query("SELECT * FROM blogs WHERE rating > $1", &[
    DbValue::I32(3),
]).await?;

Type Mapping

Rust Type PostgreSQL Type
i16 SMALLINT / SMALLSERIAL
i32 INTEGER / SERIAL
i64 BIGINT / BIGSERIAL
f32 REAL
f64 DOUBLE PRECISION
bool BOOLEAN
String TEXT / VARCHAR(n)
Vec<u8> BYTEA

Database Introspection

use lref_provider_postgres::introspection::introspect_postgres;

let tables = introspect_postgres(
    "postgres://user:pass@localhost/mydb"
).await?;

for table in &tables {
    println!("Table: {}", table.name);
    for col in &table.columns {
        println!("  {}: {} (nullable={}, pk={})",
            col.name, col.data_type, col.is_nullable, col.is_primary_key);
    }
}

SQL Dialect

  • Placeholders: $1, $2, ... (positional)
  • Identifiers: "table_name" (double-quote)
  • Pagination: OFFSET N LIMIT M
  • Auto-increment: SERIAL

License

MIT - ?see LICENSE