Connection

Struct Connection 

Source
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

Source

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.

Source

pub async fn close(self) -> Result<(), DatabaseError>

Explicitly close the connection and wait for cleanup.

Source§

impl Connection

Source

pub fn list_state_changes( &self, ) -> impl Stream<Item = StateChangeDefinitionSummary>

List all state change definitions registered with this database.

§Example
use futures::StreamExt;

let mut state_changes = conn.list_state_changes();
while let Some(sc) = state_changes.next().await {
    println!("State change: {} v{}", sc.name, sc.version);
}
Source

pub async fn fetch_transaction_by_id( &self, transaction_id: &str, ) -> Result<Transaction, DatabaseError>

Fetch a transaction by its ID.

§Example
let txn = conn.fetch_transaction_by_id("my-txn-id").await?;
println!("Transaction revision: {}", txn.summary.revision);
Source

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.

Source

pub fn transaction(&self) -> TransactionBuilder

Create a transaction builder for constructing transactions.

§Example
let db = conn
    .transaction()
    .event(my_event)
    .require_not_exists(EventSelector::stream_equals("my-stream"))
    .commit()
    .await?;
Source

pub fn state_change( &self, name: &str, version: StateChangeVersion, ) -> StateChangeBuilder

Create a state change builder for executing state changes.

§Example
let db = conn
    .state_change("create-account", 1)
    .json(&CreateAccountRequest { name: "Alice" })?
    .execute()
    .await?;

Trait Implementations§

Source§

impl Clone for Connection

Source§

fn clone(&self) -> Connection

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl DatabaseConnection for Connection

Source§

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>>

Execute a state change. Read more
Source§

fn log(&self) -> impl Stream<Item = TransactionSummary>

Get the transaction log (summary only).
Source§

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>>

Transact events with a custom transaction ID. Read more
Source§

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>

Get the transaction log with full event details, starting from a specific revision. Read more
Source§

impl DatabaseConnectionAsync for Connection

Source§

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>>

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>>

Execute a state change asynchronously. Read more
Source§

impl DatabaseIdentity for Connection

Source§

fn name(&self) -> &DatabaseName

Get the database name.
Source§

fn created_at(&self) -> DateTime<Utc>

Get the timestamp when this database was created.
Source§

impl DatabaseProvider for Connection

Source§

type AtRevision = DatabaseAtRevisionImpl

The type of database view at a specific revision.
Source§

fn local_database(&self) -> Self::AtRevision

Get the latest local database
Source§

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>>

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>>

Get the database at the revision effective at a specific timestamp.
Source§

impl Debug for Connection

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more