mod adapter;
mod introspector;
mod notify;
mod server_version;
mod tls;
mod where_generator;
#[cfg(feature = "test-postgres")]
#[doc(hidden)]
pub use adapter::test_hooks;
pub use adapter::{
HnswIterativeScan, IvfflatIterativeScan, PoolPrewarmConfig, PostgresAdapter,
READ_STATEMENT_CACHE_CAP, ReadReplicaConfig, ReadReplicaPolicy, SearchPath, VectorScanConfig,
transaction_retry::{
MAX_BACKOFF_MS, RetryEvent, RetryObserver, TransactionRetry, TransactionRetryConfig,
},
};
pub use introspector::{IndexInfo, PostgresIntrospector};
pub use notify::{NOTIFY_APPLICATION_NAME, Notification, NotifyConnector, NotifySession};
pub use server_version::{
MINIMUM_SERVER_VERSION_NUM, check_server_version, require_supported_server,
};
pub use tls::{PostgresConnector, PostgresSslMode, PostgresTlsConfig};
pub use where_generator::PostgresWhereGenerator;
pub(crate) fn pg_detail(e: &tokio_postgres::Error) -> String {
e.as_db_error().map_or_else(|| e.to_string(), |d| d.message().to_string())
}
pub(crate) fn database_error(
message: String,
e: &tokio_postgres::Error,
) -> fraiseql_error::FraiseQLError {
let constraint = e.as_db_error().and_then(|d| {
(d.constraint().is_some() || d.column().is_some()).then(|| {
Box::new(fraiseql_error::ConstraintViolation {
name: d.constraint().map(str::to_string),
schema: d.schema().map(str::to_string),
table: d.table().map(str::to_string),
column: d.column().map(str::to_string),
})
})
});
fraiseql_error::FraiseQLError::Database {
message,
sql_state: e.code().map(|c| c.code().to_string()),
constraint,
}
}