pub struct PostgresStateStore { /* private fields */ }Expand description
A StateStore that persists each entry as a row in a single Postgres
table.
The table layout is:
CREATE TABLE faucet_state (
key TEXT PRIMARY KEY,
value JSONB NOT NULL,
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);Calling PostgresStateStore::ensure_table creates the table if it does
not exist; integrators that manage schema separately can skip this call.
Implementations§
Source§impl PostgresStateStore
impl PostgresStateStore
Sourcepub async fn connect(connection_url: &str) -> Result<Self, FaucetError>
pub async fn connect(connection_url: &str) -> Result<Self, FaucetError>
Connect to a PostgreSQL server with the default faucet_state table.
Sourcepub async fn connect_with(
connection_url: &str,
max_connections: u32,
table: &str,
) -> Result<Self, FaucetError>
pub async fn connect_with( connection_url: &str, max_connections: u32, table: &str, ) -> Result<Self, FaucetError>
Connect with explicit pool size and table name.
Sourcepub fn from_pool(
pool: PgPool,
table: impl Into<String>,
) -> Result<Self, FaucetError>
pub fn from_pool( pool: PgPool, table: impl Into<String>, ) -> Result<Self, FaucetError>
Construct from an existing pool. Useful when integrators already
manage a shared PgPool.
Sourcepub async fn ensure_table(&self) -> Result<(), FaucetError>
pub async fn ensure_table(&self) -> Result<(), FaucetError>
Create the state-store table if it does not already exist.
Trait Implementations§
Source§impl StateStore for PostgresStateStore
impl StateStore for PostgresStateStore
Source§fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Value>, FaucetError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Value>, FaucetError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Return the value stored under
key, or None if no entry exists.Source§fn put<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
key: &'life1 str,
value: &'life2 Value,
) -> Pin<Box<dyn Future<Output = Result<(), FaucetError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn put<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
key: &'life1 str,
value: &'life2 Value,
) -> Pin<Box<dyn Future<Output = Result<(), FaucetError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Source§fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), FaucetError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), FaucetError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Remove the entry for
key. A missing key is not an error.Source§fn check<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 CheckContext,
) -> Pin<Box<dyn Future<Output = Result<CheckReport, FaucetError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn check<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 CheckContext,
) -> Pin<Box<dyn Future<Output = Result<CheckReport, FaucetError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Run a fast, non-mutating preflight probe (used by
faucet doctor). Read moreAuto Trait Implementations§
impl Freeze for PostgresStateStore
impl !RefUnwindSafe for PostgresStateStore
impl Send for PostgresStateStore
impl Sync for PostgresStateStore
impl Unpin for PostgresStateStore
impl UnsafeUnpin for PostgresStateStore
impl !UnwindSafe for PostgresStateStore
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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