pub struct PostgresIndexBackend {
pool: Pool,
table_name: String,
}Expand description
PostgreSQL-based index backend.
Uses deadpool_postgres::Pool for thread-safe connection pooling,
enabling &self methods without interior mutability wrappers.
Fields§
§pool: PoolConnection pool (thread-safe via internal Arc).
table_name: StringTable name for memories (validated against whitelist).
Implementations§
Source§impl PostgresIndexBackend
impl PostgresIndexBackend
Sourceconst POOL_MAX_SIZE: usize = 20usize
const POOL_MAX_SIZE: usize = 20usize
Maximum connections in pool (CHAOS-H1).
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 index backend with TLS encryption (COMP-C3).
Uses rustls for TLS connections. The connection URL should include
sslmode=require or sslmode=verify-full for production use.
§Errors
Returns an error if the connection pool fails to initialize, if TLS configuration fails, or if the table name is not allowed.
Sourcefn root_cert_store() -> RootCertStore
fn root_cert_store() -> RootCertStore
Builds root certificate store for TLS.
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 (SEC-M2).
Validates the URL for security before parsing to prevent injection attacks.
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) -> Config
fn build_pool_config(config: &Config) -> Config
Builds a deadpool config from tokio-postgres config.
§Pool Exhaustion Protection (CHAOS-H1)
Configures connection pool with safety limits:
- Max 20 connections (prevents pool exhaustion)
- Runtime pool builder sets timeouts for wait/create/recycle
§Statement Caching (DB-H4)
Statement caching is handled automatically by tokio-postgres connections.
Each connection maintains its own prepared statement cache. The
RecyclingMethod::Fast setting preserves connections (and their statement
caches) across uses, providing implicit statement caching without
additional configuration.
Sourcepub fn with_defaults() -> Result<Self>
pub fn with_defaults() -> Result<Self>
Sourcefn run_migrations(&self) -> Result<()>
fn run_migrations(&self) -> Result<()>
Runs migrations.
Sourcefn build_where_clause(
filter: &SearchFilter,
start_param: i32,
) -> (String, Vec<String>)
fn build_where_clause( filter: &SearchFilter, start_param: i32, ) -> (String, Vec<String>)
Builds WHERE clause for filters.
Sourcefn add_namespace_filter(
filter: &SearchFilter,
clauses: &mut Vec<String>,
params: &mut Vec<String>,
param_num: &mut i32,
)
fn add_namespace_filter( filter: &SearchFilter, clauses: &mut Vec<String>, params: &mut Vec<String>, param_num: &mut i32, )
Adds namespace filter to WHERE clause.
Sourcefn add_domain_filter(
filter: &SearchFilter,
clauses: &mut Vec<String>,
params: &mut Vec<String>,
param_num: &mut i32,
)
fn add_domain_filter( filter: &SearchFilter, clauses: &mut Vec<String>, params: &mut Vec<String>, param_num: &mut i32, )
Adds domain filter to WHERE clause.
Sourcefn add_status_filter(
filter: &SearchFilter,
clauses: &mut Vec<String>,
params: &mut Vec<String>,
param_num: &mut i32,
)
fn add_status_filter( filter: &SearchFilter, clauses: &mut Vec<String>, params: &mut Vec<String>, param_num: &mut i32, )
Adds status filter to WHERE clause.
fn add_project_filter( filter: &SearchFilter, clauses: &mut Vec<String>, params: &mut Vec<String>, param_num: &mut i32, )
fn add_branch_filter( filter: &SearchFilter, clauses: &mut Vec<String>, params: &mut Vec<String>, param_num: &mut i32, )
fn add_file_path_filter( filter: &SearchFilter, clauses: &mut Vec<String>, params: &mut Vec<String>, param_num: &mut i32, )
Sourceasync fn index_async(&self, memory: &Memory) -> Result<()>
async fn index_async(&self, memory: &Memory) -> Result<()>
Async implementation of index operation.
Sourceasync fn remove_async(&self, id: &MemoryId) -> Result<bool>
async fn remove_async(&self, id: &MemoryId) -> Result<bool>
Async implementation of remove operation.
Sourceasync fn search_async(
&self,
query: &str,
filter: &SearchFilter,
limit: usize,
) -> Result<Vec<(MemoryId, f32)>>
async fn search_async( &self, query: &str, filter: &SearchFilter, limit: usize, ) -> Result<Vec<(MemoryId, f32)>>
Async implementation of search operation.
Sourceasync fn list_all_async(
&self,
filter: &SearchFilter,
limit: usize,
) -> Result<Vec<(MemoryId, f32)>>
async fn list_all_async( &self, filter: &SearchFilter, limit: usize, ) -> Result<Vec<(MemoryId, f32)>>
Async implementation of list_all operation.
Sourceasync fn clear_async(&self) -> Result<()>
async fn clear_async(&self) -> Result<()>
Async implementation of clear operation.
Trait Implementations§
Source§impl IndexBackend for PostgresIndexBackend
impl IndexBackend for PostgresIndexBackend
Source§fn index(&self, memory: &Memory) -> Result<()>
fn index(&self, memory: &Memory) -> Result<()>
Source§fn search(
&self,
query: &str,
filter: &SearchFilter,
limit: usize,
) -> Result<Vec<(MemoryId, f32)>>
fn search( &self, query: &str, filter: &SearchFilter, limit: usize, ) -> Result<Vec<(MemoryId, f32)>>
Source§fn list_all(
&self,
filter: &SearchFilter,
limit: usize,
) -> Result<Vec<(MemoryId, f32)>>
fn list_all( &self, filter: &SearchFilter, limit: usize, ) -> Result<Vec<(MemoryId, f32)>>
Auto Trait Implementations§
impl Freeze for PostgresIndexBackend
impl !RefUnwindSafe for PostgresIndexBackend
impl Send for PostgresIndexBackend
impl Sync for PostgresIndexBackend
impl Unpin for PostgresIndexBackend
impl !UnwindSafe for PostgresIndexBackend
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].