Skip to main content

PqsClient

Struct PqsClient 

Source
pub struct PqsClient { /* private fields */ }
Expand description

A read client for a PQS database.

Cloning is cheap and clones share the connection, which pipelines concurrent queries — so pooling is the application’s decision rather than this crate’s, as telemetry is.

Implementations§

Source§

impl PqsClient

Source

pub async fn connect(config: &str) -> Result<Self>

Connect without TLS.

config is a libpq connection string — host=… user=… password=… dbname=… — or a postgres:// URL. The connection is driven on a spawned task; dropping every clone of the client ends it.

§Errors

Error::Connection if the store cannot be reached, and Error::InvalidRequest if it refuses the connection for a reason waiting will not change — a wrong password, an unknown database.

Source

pub async fn connect_with_timeout( config: &str, timeout: Duration, ) -> Result<Self>

connect with an explicit deadline for the attempt, which also becomes the per-query timeout.

§Errors

As connect, plus Error::Timeout if the store did not answer within timeout.

Source

pub async fn connect_tls(config: &str) -> Result<Self>

Available on crate feature tls only.

Connect over TLS, with the platform’s root certificates.

§Errors

Error::Connection if the store cannot be reached, and Error::InvalidRequest if no root certificates can be loaded, if the certificate cannot be verified, or if the store refuses the connection for a reason waiting will not change.

Source

pub async fn connect_tls_with_timeout( config: &str, timeout: Duration, ) -> Result<Self>

Available on crate feature tls only.

connect_tls with an explicit deadline for the attempt, which also becomes the per-query timeout.

TLS is required, not preferred: a store that answers the TLS request with “no” is an error here, never a silent plaintext session. tokio-postgres’s own default is sslmode=prefer, which is exactly that silent fallback, and a connection string carrying sslmode=disable would otherwise turn this method into connect.

§Errors

As connect_tls, plus Error::Timeout if the store did not answer within timeout.

Source

pub fn with_timeout(self, timeout: Duration) -> Self

Change the deadline for every query (and reconnect) on this client and its clones. The default is DEFAULT_TIMEOUT.

Source

pub async fn run<T>(&self, query: &Query<T>) -> Result<Vec<Contract<T>>>

Run a query and decode every row.

§Errors

Error::Connection if the query fails, or a decoding error if a row does not match T.

Source

pub async fn active<T>(&self) -> Result<Vec<Contract<T>>>

The active contracts of a template, unfiltered.

§Errors

As run.

Source

pub async fn lookup<T>(&self, contract_id: &str) -> Result<Option<Contract<T>>>

One contract by id, or None if PQS does not have it.

Reads lookup_contract, which finds a contract whether it is active or archived — unlike a filter on active().

§Errors

As run.

Source

pub async fn exercises<T, C>( &self, from: Option<i64>, to: Option<i64>, ) -> Result<Vec<Exercise<C>>>

The exercises of one choice, in a range of offsets.

The choice’s name is taken from the type, as a template’s qname is.

§Errors

As run.

Source

pub async fn latest_offset(&self) -> Result<i64>

The latest offset PQS has ingested.

What a caller reads to know how far behind the store is, and what to pass to Query::active_at for a stable read.

§Errors

As run.

Source

pub async fn query(&self, sql: &Sql) -> Result<Vec<Row>>

Run a compiled statement.

§Errors

Error::Connection if the query fails.

Trait Implementations§

Source§

impl Clone for PqsClient

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for PqsClient

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> 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<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = !

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

fn try_from(value: U) -> Result<T, !>

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