pub struct PgGraph { /* private fields */ }Expand description
PostgreSQL-backed GraphBackend over one mutex-guarded connection.
Opening applies the schema and runs pending migrations, matching
SqliteGraph::open in the main crate. An optional table_prefix
(empty by default) namespaces every backing table and index so multiple
graphs can share one database — see the *_with_prefix constructors.
Implementations§
Source§impl PgGraph
impl PgGraph
Sourcepub fn connect(url: &str) -> Result<Self>
pub fn connect(url: &str) -> Result<Self>
Connect to url (libpq connstring or postgresql:// URL), apply schema
and migrations, and return a ready backend. Uses the default (empty)
table prefix.
Sourcepub fn connect_with_prefix(url: &str, prefix: &str) -> Result<Self>
pub fn connect_with_prefix(url: &str, prefix: &str) -> Result<Self>
Like connect, but every table/index is namespaced
under prefix (e.g. "lk_" → lk_nodes / lk_edges / lk_meta).
The prefix is validated by is_identifier_safe before any SQL runs.
Sourcepub fn connect_config(config: &Config) -> Result<Self>
pub fn connect_config(config: &Config) -> Result<Self>
Connect from a pre-built Config (useful for overriding dbname,
e.g. when targeting a throwaway test database). Uses the default
(empty) table prefix.
Sourcepub fn connect_config_with_prefix(config: &Config, prefix: &str) -> Result<Self>
pub fn connect_config_with_prefix(config: &Config, prefix: &str) -> Result<Self>
Like connect_config, but every table/index is
namespaced under prefix.
Sourcepub fn connect_tls<T>(url: &str, connector: T) -> Result<Self>where
T: MakeTlsConnect<Socket> + Send + 'static,
T::TlsConnect: Send,
T::Stream: Send,
<T::TlsConnect as TlsConnect<Socket>>::Future: Send,
pub fn connect_tls<T>(url: &str, connector: T) -> Result<Self>where
T: MakeTlsConnect<Socket> + Send + 'static,
T::TlsConnect: Send,
T::Stream: Send,
<T::TlsConnect as TlsConnect<Socket>>::Future: Send,
Connect to url using a caller-supplied TLS connector — for servers
requiring sslmode=require or stricter (e.g. RDS with
rds.force_ssl). See Self::connect_native_tls for the common case
of a system-trust-store native-tls connector. Uses the default
(empty) table prefix.
Sourcepub fn connect_tls_with_prefix<T>(
url: &str,
prefix: &str,
connector: T,
) -> Result<Self>where
T: MakeTlsConnect<Socket> + Send + 'static,
T::TlsConnect: Send,
T::Stream: Send,
<T::TlsConnect as TlsConnect<Socket>>::Future: Send,
pub fn connect_tls_with_prefix<T>(
url: &str,
prefix: &str,
connector: T,
) -> Result<Self>where
T: MakeTlsConnect<Socket> + Send + 'static,
T::TlsConnect: Send,
T::Stream: Send,
<T::TlsConnect as TlsConnect<Socket>>::Future: Send,
TLS variant of connect_with_prefix with a
caller-supplied TLS connector.
Sourcepub fn connect_config_tls<T>(config: &Config, connector: T) -> Result<Self>where
T: MakeTlsConnect<Socket> + Send + 'static,
T::TlsConnect: Send,
T::Stream: Send,
<T::TlsConnect as TlsConnect<Socket>>::Future: Send,
pub fn connect_config_tls<T>(config: &Config, connector: T) -> Result<Self>where
T: MakeTlsConnect<Socket> + Send + 'static,
T::TlsConnect: Send,
T::Stream: Send,
<T::TlsConnect as TlsConnect<Socket>>::Future: Send,
Connect from a pre-built Config using a caller-supplied TLS
connector. Mirrors Self::connect_config but negotiates TLS instead
of postgres::NoTls. Uses the default (empty) table prefix.
Sourcepub fn connect_config_tls_with_prefix<T>(
config: &Config,
prefix: &str,
connector: T,
) -> Result<Self>where
T: MakeTlsConnect<Socket> + Send + 'static,
T::TlsConnect: Send,
T::Stream: Send,
<T::TlsConnect as TlsConnect<Socket>>::Future: Send,
pub fn connect_config_tls_with_prefix<T>(
config: &Config,
prefix: &str,
connector: T,
) -> Result<Self>where
T: MakeTlsConnect<Socket> + Send + 'static,
T::TlsConnect: Send,
T::Stream: Send,
<T::TlsConnect as TlsConnect<Socket>>::Future: Send,
TLS variant of connect_config_with_prefix
with a caller-supplied TLS connector.
Sourcepub fn connect_native_tls(url: &str) -> Result<Self>
pub fn connect_native_tls(url: &str) -> Result<Self>
Connect to url over TLS using native-tls with the system trust
store (default settings — full certificate chain and hostname
verification against the system trust store, not weakened) — covers
the common case of a Postgres server with a publicly-trusted
certificate (e.g. RDS sslmode=require). For custom CA bundles or
client certificates, build a connector and call Self::connect_tls
directly. Uses the default (empty) table prefix.
Sourcepub fn connect_native_tls_with_prefix(url: &str, prefix: &str) -> Result<Self>
pub fn connect_native_tls_with_prefix(url: &str, prefix: &str) -> Result<Self>
TLS variant of connect_with_prefix using
native-tls with the system trust store.
Sourcepub fn from_client(client: Client) -> Result<Self>
pub fn from_client(client: Client) -> Result<Self>
Shared post-connect setup (schema + migrations) for every constructor.
Public so a consumer that already owns a synchronous postgres::Client
can adopt PgGraph without re-opening the connection. For an async
pool (e.g. sqlx::PgPool), use the planned SqlxPgGraph backend instead.
Uses the default (empty) table prefix.
Sourcepub fn from_client_with_prefix(client: Client, prefix: &str) -> Result<Self>
pub fn from_client_with_prefix(client: Client, prefix: &str) -> Result<Self>
Like from_client, but every table/index is
namespaced under prefix. The prefix is validated first; an unsafe
value (anything beyond ASCII alphanumeric / underscore, or a digit-led
name) returns KernelError::Store before any SQL is emitted.
Trait Implementations§
Source§impl GraphBackend for PgGraph
impl GraphBackend for PgGraph
Source§fn read_node(&self, id: &str) -> Result<Option<GraphNode>>
fn read_node(&self, id: &str) -> Result<Option<GraphNode>>
None if absent).Source§fn delete_node(&self, id: &str) -> Result<bool>
fn delete_node(&self, id: &str) -> Result<bool>
true if a row was removed.Source§fn search_nodes(&self, query: &str, limit: usize) -> Result<Vec<GraphNode>>
fn search_nodes(&self, query: &str, limit: usize) -> Result<Vec<GraphNode>>
Source§fn query_nodes(
&self,
tag: Option<&str>,
node_type: Option<&str>,
project: Option<&str>,
limit: usize,
) -> Result<Vec<GraphNode>>
fn query_nodes( &self, tag: Option<&str>, node_type: Option<&str>, project: Option<&str>, limit: usize, ) -> Result<Vec<GraphNode>>
Source§fn smart_recall(
&self,
project: Option<&str>,
hint: Option<&str>,
limit: usize,
) -> Result<Vec<ScoredNode>>
fn smart_recall( &self, project: Option<&str>, hint: Option<&str>, limit: usize, ) -> Result<Vec<ScoredNode>>
depth hops from start_id, returning related node
IDs (excluding the start).Source§fn append_edge(&self, edge: &GraphEdge) -> Result<()>
fn append_edge(&self, edge: &GraphEdge) -> Result<()>
Source§fn append_edges(&self, edges: &[GraphEdge]) -> Result<()>
fn append_edges(&self, edges: &[GraphEdge]) -> Result<()>
Source§fn edges_for_node_dir(
&self,
node_id: &str,
dir: EdgeDirection,
relation: Option<&str>,
) -> Result<Vec<GraphEdge>>
fn edges_for_node_dir( &self, node_id: &str, dir: EdgeDirection, relation: Option<&str>, ) -> Result<Vec<GraphEdge>>
node_id, filtered by direction and an optional
relation. The default implementation reads both directions via
Self::edges_for_node and filters in Rust; backends with directional
indexes override for efficiency.Source§fn neighbors_weighted(
&self,
seed_ids: &[String],
dir: EdgeDirection,
relation: Option<&str>,
) -> Result<Vec<(String, f64)>>
fn neighbors_weighted( &self, seed_ids: &[String], dir: EdgeDirection, relation: Option<&str>, ) -> Result<Vec<(String, f64)>>
seed_ids (weighted sum), restricted by direction
and an optional relation. Seed nodes are excluded. The default
implementation walks each seed via Self::edges_for_node_dir.Source§fn edges_for_node(&self, node_id: &str) -> Result<Vec<GraphEdge>>
fn edges_for_node(&self, node_id: &str) -> Result<Vec<GraphEdge>>
Source§fn delete_edge(&self, id: &str) -> Result<bool>
fn delete_edge(&self, id: &str) -> Result<bool>
true if a row was removed.Source§fn remove_edges_for_node(&self, node_id: &str) -> Result<()>
fn remove_edges_for_node(&self, node_id: &str) -> Result<()>
Source§fn current_version(&self) -> Result<u32>
fn current_version(&self) -> Result<u32>
Source§fn migrate(&self) -> Result<u32>
fn migrate(&self) -> Result<u32>
depth hops from start_id, returning related node
IDs (excluding the start), restricted by direction and an optional
relation. The default implementation hops via Self::neighbors_weighted.Auto Trait Implementations§
impl !Freeze for PgGraph
impl RefUnwindSafe for PgGraph
impl Send for PgGraph
impl Sync for PgGraph
impl Unpin for PgGraph
impl UnsafeUnpin for PgGraph
impl UnwindSafe for PgGraph
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.