pub struct PostgresBackend {
pool: Pool,
table_name: String,
}Expand description
PostgreSQL-based persistence backend.
Fields§
§pool: PoolConnection pool.
table_name: StringTable name for memories.
Implementations§
Source§impl PostgresBackend
impl PostgresBackend
Sourceconst DEFAULT_POOL_MAX_SIZE: usize = 20
const DEFAULT_POOL_MAX_SIZE: usize = 20
Default maximum connections in pool.
Sourcepub fn new(connection_url: &str, table_name: impl Into<String>) -> Result<Self>
pub fn new(connection_url: &str, table_name: impl Into<String>) -> Result<Self>
Creates a new PostgreSQL backend.
§Errors
Returns an error if the connection pool fails to initialize.
Sourcepub fn with_pool_size(
connection_url: &str,
table_name: impl Into<String>,
pool_max_size: Option<usize>,
) -> Result<Self>
pub fn with_pool_size( connection_url: &str, table_name: impl Into<String>, pool_max_size: Option<usize>, ) -> Result<Self>
Creates a new PostgreSQL backend with configurable pool size.
§Arguments
connection_url- PostgreSQL connection URLtable_name- Name of the table for storing memoriespool_max_size- Maximum connections in pool (defaults to 20)
§Errors
Returns an error if the connection pool fails to initialize after retries.
§Connection Retry (CHAOS-HIGH-003)
Connection establishment uses exponential backoff with jitter for transient failures. This handles scenarios where the database is starting up or temporarily unavailable.
Sourcefn parse_connection_url(url: &str) -> Result<Config>
fn parse_connection_url(url: &str) -> Result<Config>
Parses the connection URL into a tokio-postgres config.
Sourcefn host_to_string(h: &Host) -> String
fn host_to_string(h: &Host) -> String
Extracts host string from tokio-postgres Host.
Sourcefn build_pool_config(config: &Config, pool_max_size: Option<usize>) -> Config
fn build_pool_config(config: &Config, pool_max_size: Option<usize>) -> Config
Builds a deadpool config from tokio-postgres config.
§Pool Configuration (HIGH-010, DB-M2)
Configures connection pool with safety limits:
- Configurable max connections (defaults to 20, prevents pool exhaustion)
- 5 second acquire timeout (prevents hanging on pool exhaustion)
Pool size can be configured via StorageBackendConfig.pool_max_size.
Sourcepub fn with_defaults() -> Result<Self>
pub fn with_defaults() -> Result<Self>
Sourcefn run_migrations(&self) -> Result<()>
fn run_migrations(&self) -> Result<()>
Runs migrations.
Sourceasync fn store_async(&self, memory: &Memory) -> Result<()>
async fn store_async(&self, memory: &Memory) -> Result<()>
Async implementation of store operation.
Sourceasync fn get_async(&self, id: &MemoryId) -> Result<Option<Memory>>
async fn get_async(&self, id: &MemoryId) -> Result<Option<Memory>>
Async implementation of get operation.
Sourcefn row_to_memory(row: &Row) -> Memory
fn row_to_memory(row: &Row) -> Memory
Converts a database row to a Memory.
Sourceasync fn delete_async(&self, id: &MemoryId) -> Result<bool>
async fn delete_async(&self, id: &MemoryId) -> Result<bool>
Async implementation of delete operation.
Sourceasync fn list_ids_async(&self) -> Result<Vec<MemoryId>>
async fn list_ids_async(&self) -> Result<Vec<MemoryId>>
Async implementation of list_ids operation.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PostgresBackend
impl !RefUnwindSafe for PostgresBackend
impl Send for PostgresBackend
impl Sync for PostgresBackend
impl Unpin for PostgresBackend
impl !UnwindSafe for PostgresBackend
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].