pub struct PostgresAdapter { /* private fields */ }Expand description
PostgreSQL database adapter with connection pooling.
Uses deadpool-postgres for connection pooling and tokio-postgres for async queries.
§Example
use fraiseql_core::db::postgres::PostgresAdapter;
use fraiseql_core::db::{DatabaseAdapter, WhereClause, WhereOperator};
use serde_json::json;
// Create adapter with connection string
let adapter = PostgresAdapter::new("postgresql://localhost/mydb").await?;
// Execute query
let where_clause = WhereClause::Field {
path: vec!["email".to_string()],
operator: WhereOperator::Icontains,
value: json!("example.com"),
};
let results = adapter
.execute_where_query("v_user", Some(&where_clause), Some(10), None)
.await?;
println!("Found {} users", results.len());Implementations§
Source§impl PostgresAdapter
impl PostgresAdapter
Sourcepub async fn new(connection_string: &str) -> Result<Self>
pub async fn new(connection_string: &str) -> Result<Self>
Create new PostgreSQL adapter with default pool configuration.
§Arguments
connection_string- PostgreSQL connection string (e.g., “postgresql://localhost/mydb”)
§Errors
Returns FraiseQLError::ConnectionPool if pool creation fails.
§Example
let adapter = PostgresAdapter::new("postgresql://localhost/mydb").await?;Sourcepub async fn with_pool_config(
connection_string: &str,
_min_size: usize,
max_size: usize,
) -> Result<Self>
pub async fn with_pool_config( connection_string: &str, _min_size: usize, max_size: usize, ) -> Result<Self>
Create new PostgreSQL adapter with custom pool configuration.
§Arguments
connection_string- PostgreSQL connection stringmin_size- Minimum size hint (not enforced by deadpool-postgres)max_size- Maximum number of connections in pool
§Errors
Returns FraiseQLError::ConnectionPool if pool creation fails.
§Note
min_size is accepted for API compatibility but deadpool-postgres uses
lazy initialization with dynamic pool sizing up to max_size.
Sourcepub async fn with_pool_size(
connection_string: &str,
max_size: usize,
) -> Result<Self>
pub async fn with_pool_size( connection_string: &str, max_size: usize, ) -> Result<Self>
Sourcepub fn pool(&self) -> &Pool
pub fn pool(&self) -> &Pool
Get a reference to the internal connection pool.
This allows sharing the pool with other components like PostgresIntrospector.
Sourcepub async fn execute_with_projection(
&self,
view: &str,
projection: Option<&SqlProjectionHint>,
where_clause: Option<&WhereClause>,
limit: Option<u32>,
) -> Result<Vec<JsonbValue>>
pub async fn execute_with_projection( &self, view: &str, projection: Option<&SqlProjectionHint>, where_clause: Option<&WhereClause>, limit: Option<u32>, ) -> Result<Vec<JsonbValue>>
Execute query with SQL field projection optimization.
Uses the provided SqlProjectionHint to generate optimized SQL that projects
only the requested fields from the JSONB column, reducing network payload and
JSON deserialization overhead.
§Arguments
view- View/table name to queryprojection- Optional SQL projection hint with field listwhere_clause- Optional WHERE clause for filteringlimit- Optional row limit
§Returns
Vector of projected JSONB rows with only the requested fields
§Errors
Returns FraiseQLError::Database on query execution failure.
§Example
let projection = SqlProjectionHint {
database: "postgresql".to_string(),
projection_template: "...".to_string(),
estimated_reduction_percent: 75,
};
let results = adapter
.execute_with_projection("v_user", Some(&projection), None, Some(10))
.await?;Trait Implementations§
Source§impl Clone for PostgresAdapter
impl Clone for PostgresAdapter
Source§fn clone(&self) -> PostgresAdapter
fn clone(&self) -> PostgresAdapter
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more