pub struct Connection { /* private fields */ }Expand description
A connection to an EvidentSource database with live metadata updates.
The connection maintains a background subscription to receive database updates whenever transactions are committed. This enables efficient access to the latest database state without polling.
§Example
ⓘ
let es = EvidentSource::connect_to_server("http://localhost:50051").await?;
let conn = es.connect(&DatabaseName::new("my-db")?).await?;
// Get latest database state
let db = conn.latest_database().await?;
println!("Revision: {}", db.revision());Implementations§
Source§impl Connection
impl Connection
Sourcepub async fn new(
client: EvidentSourceClient,
database_name: DatabaseName,
) -> Result<Self, DatabaseError>
pub async fn new( client: EvidentSourceClient, database_name: DatabaseName, ) -> Result<Self, DatabaseError>
Create a new connection to a database.
This fetches the initial database state and starts a background subscription to receive updates.
Sourcepub async fn close(self) -> Result<(), DatabaseError>
pub async fn close(self) -> Result<(), DatabaseError>
Explicitly close the connection and wait for cleanup.
Source§impl Connection
impl Connection
Sourcepub fn list_state_changes(
&self,
) -> impl Stream<Item = StateChangeDefinitionSummary>
pub fn list_state_changes( &self, ) -> impl Stream<Item = StateChangeDefinitionSummary>
Sourcepub async fn fetch_transaction_by_id(
&self,
transaction_id: &str,
) -> Result<Transaction, DatabaseError>
pub async fn fetch_transaction_by_id( &self, transaction_id: &str, ) -> Result<Transaction, DatabaseError>
Sourcepub fn client(&self) -> &EvidentSourceClient
pub fn client(&self) -> &EvidentSourceClient
Get a reference to the underlying gRPC client.
This provides access to low-level operations not exposed through the high-level API.
Sourcepub fn transaction(&self) -> TransactionBuilder
pub fn transaction(&self) -> TransactionBuilder
Sourcepub fn state_change(
&self,
name: &str,
version: StateChangeVersion,
) -> StateChangeBuilder
pub fn state_change( &self, name: &str, version: StateChangeVersion, ) -> StateChangeBuilder
Trait Implementations§
Source§impl Clone for Connection
impl Clone for Connection
Source§fn clone(&self) -> Connection
fn clone(&self) -> Connection
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl DatabaseConnection for Connection
impl DatabaseConnection for Connection
Source§fn transact(
&self,
events: NonEmpty<ProspectiveEvent>,
conditions: Vec<AppendCondition>,
) -> impl Future<Output = Result<Self::AtRevision, DatabaseError>>
fn transact( &self, events: NonEmpty<ProspectiveEvent>, conditions: Vec<AppendCondition>, ) -> impl Future<Output = Result<Self::AtRevision, DatabaseError>>
Transact events with append conditions. Read more
Source§fn execute_state_change(
&self,
name: &StateChangeName,
version: StateChangeVersion,
request: CommandRequest,
) -> impl Future<Output = Result<Self::AtRevision, StateChangeError>>
fn execute_state_change( &self, name: &StateChangeName, version: StateChangeVersion, request: CommandRequest, ) -> impl Future<Output = Result<Self::AtRevision, StateChangeError>>
Execute a state change. Read more
Source§fn log(&self) -> impl Stream<Item = TransactionSummary>
fn log(&self) -> impl Stream<Item = TransactionSummary>
Get the transaction log (summary only).
Source§fn log_detail(&self) -> impl Stream<Item = Transaction>
fn log_detail(&self) -> impl Stream<Item = Transaction>
Get the transaction log with full event details.
Source§fn transact_with_id(
&self,
transaction_id: &str,
events: NonEmpty<ProspectiveEvent>,
conditions: Vec<AppendCondition>,
) -> impl Future<Output = Result<Self::AtRevision, DatabaseError>>
fn transact_with_id( &self, transaction_id: &str, events: NonEmpty<ProspectiveEvent>, conditions: Vec<AppendCondition>, ) -> impl Future<Output = Result<Self::AtRevision, DatabaseError>>
Transact events with a custom transaction ID. Read more
Source§fn log_from(
&self,
from_revision: Revision,
) -> impl Stream<Item = TransactionSummary>
fn log_from( &self, from_revision: Revision, ) -> impl Stream<Item = TransactionSummary>
Get the transaction log starting from a specific revision. Read more
Source§fn log_detail_from(
&self,
from_revision: Revision,
) -> impl Stream<Item = Transaction>
fn log_detail_from( &self, from_revision: Revision, ) -> impl Stream<Item = Transaction>
Get the transaction log with full event details, starting from a specific revision. Read more
Source§impl DatabaseConnectionAsync for Connection
impl DatabaseConnectionAsync for Connection
Source§fn transact_async(
&self,
events: NonEmpty<ProspectiveEvent>,
conditions: Vec<AppendCondition>,
) -> impl Future<Output = Result<CorrelationId, DatabaseError>>
fn transact_async( &self, events: NonEmpty<ProspectiveEvent>, conditions: Vec<AppendCondition>, ) -> impl Future<Output = Result<CorrelationId, DatabaseError>>
Transact asynchronously. Read more
Source§fn transact_async_with_id(
&self,
transaction_id: &str,
events: NonEmpty<ProspectiveEvent>,
conditions: Vec<AppendCondition>,
) -> impl Future<Output = Result<CorrelationId, DatabaseError>>
fn transact_async_with_id( &self, transaction_id: &str, events: NonEmpty<ProspectiveEvent>, conditions: Vec<AppendCondition>, ) -> impl Future<Output = Result<CorrelationId, DatabaseError>>
Transact asynchronously with a specific transaction ID.
Source§fn execute_state_change_async(
&self,
name: &StateChangeName,
version: StateChangeVersion,
request: CommandRequest,
) -> impl Future<Output = Result<CorrelationId, StateChangeError>>
fn execute_state_change_async( &self, name: &StateChangeName, version: StateChangeVersion, request: CommandRequest, ) -> impl Future<Output = Result<CorrelationId, StateChangeError>>
Execute a state change asynchronously. Read more
Source§impl DatabaseIdentity for Connection
impl DatabaseIdentity for Connection
Source§fn name(&self) -> &DatabaseName
fn name(&self) -> &DatabaseName
Get the database name.
Source§fn created_at(&self) -> DateTime<Utc>
fn created_at(&self) -> DateTime<Utc>
Get the timestamp when this database was created.
Source§impl DatabaseProvider for Connection
impl DatabaseProvider for Connection
Source§type AtRevision = DatabaseAtRevisionImpl
type AtRevision = DatabaseAtRevisionImpl
The type of database view at a specific revision.
Source§fn local_database(&self) -> Self::AtRevision
fn local_database(&self) -> Self::AtRevision
Get the latest local database
Source§fn latest_database(
&self,
) -> impl Future<Output = Result<Self::AtRevision, DatabaseError>>
fn latest_database( &self, ) -> impl Future<Output = Result<Self::AtRevision, DatabaseError>>
Get the latest revision on the server committed to storage.
Source§fn database_at_revision(
&self,
revision: u64,
) -> impl Future<Output = Result<Self::AtRevision, DatabaseError>>
fn database_at_revision( &self, revision: u64, ) -> impl Future<Output = Result<Self::AtRevision, DatabaseError>>
Get the database at a specific revision, awaiting if necessary.
Source§fn database_at_timestamp(
&self,
revision_timestamp: DateTime<Utc>,
) -> impl Future<Output = Result<Self::AtRevision, DatabaseError>>
fn database_at_timestamp( &self, revision_timestamp: DateTime<Utc>, ) -> impl Future<Output = Result<Self::AtRevision, DatabaseError>>
Get the database at the revision effective at a specific timestamp.
Auto Trait Implementations§
impl Freeze for Connection
impl !RefUnwindSafe for Connection
impl Send for Connection
impl Sync for Connection
impl Unpin for Connection
impl !UnwindSafe for Connection
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request