Skip to main content

AnnotatedQuery

Struct AnnotatedQuery 

Source
pub struct AnnotatedQuery<Q> { /* private fields */ }
Expand description

A SQLx query builder paired with OpenTelemetry per-query annotations.

Produced by QueryAnnotateExt::with_annotations / QueryAnnotateExt::with_operation. Each invocation of the executor-driven methods (execute, fetch_all, etc.) wraps the executor with the annotations so the resulting span carries them.

The wrapper exposes bind so the caller can chain .bind(...).with_annotations(...) or .with_annotations(...).bind(...) interchangeably.

Implementations§

Source§

impl<'q, DB, A> AnnotatedQuery<Query<'q, DB, A>>
where DB: Database, A: 'q + Send + IntoArguments<'q, DB>,

Source

pub fn with_annotations(self, annotations: QueryAnnotations) -> Self

Replace the wrapper’s annotations. Last-call-wins – any previously set annotations on this wrapper are discarded.

Source

pub fn with_operation( self, operation: impl Into<String>, collection: impl Into<String>, ) -> Self

Shorthand replacement that sets db.operation.name and db.collection.name. Discards any previously set annotations on this wrapper.

Source

pub fn fetch<'e, E>(self, executor: E) -> BoxStream<'e, Result<DB::Row, Error>>
where A: 'e, E: 'e + IntoAnnotatedExecutor<'e, DB>, 'q: 'e,

Stream the resulting rows.

Source

pub fn fetch_many<'e, E>( self, executor: E, ) -> BoxStream<'e, Result<Either<DB::QueryResult, DB::Row>, Error>>
where A: 'e, E: 'e + IntoAnnotatedExecutor<'e, DB>, 'q: 'e,

Stream a mix of QueryResults and rows for multi-statement queries.

fetch_many is #[deprecated] in SQLx 0.8 but kept for parity with the executor-side surface.

Source

pub fn fetch_all<'e, E>( self, executor: E, ) -> impl 'e + Send + Future<Output = Result<Vec<DB::Row>, Error>>
where A: 'e, E: 'e + IntoAnnotatedExecutor<'e, DB>, 'q: 'e,

Collect every row into a Vec.

§Errors

Returns any sqlx::Error surfaced by the underlying driver, including row decoding errors.

Source

pub fn fetch_one<'e, E>( self, executor: E, ) -> impl 'e + Send + Future<Output = Result<DB::Row, Error>>
where A: 'e, E: 'e + IntoAnnotatedExecutor<'e, DB>, 'q: 'e,

Return exactly one row, erroring if none or more than one.

§Errors

Returns sqlx::Error::RowNotFound when the result set is empty, or any other sqlx::Error surfaced by the underlying driver.

Source

pub fn fetch_optional<'e, E>( self, executor: E, ) -> impl 'e + Send + Future<Output = Result<Option<DB::Row>, Error>>
where A: 'e, E: 'e + IntoAnnotatedExecutor<'e, DB>, 'q: 'e,

Return at most one row.

§Errors

Returns any sqlx::Error surfaced by the underlying driver.

Source

pub fn execute<'e, E>( self, executor: E, ) -> impl 'e + Send + Future<Output = Result<DB::QueryResult, Error>>
where A: 'e, E: 'e + IntoAnnotatedExecutor<'e, DB>, 'q: 'e,

Execute the query and return the number of rows affected. Wraps the executor with the carried annotations so the resulting span is annotated.

§Errors

Returns any sqlx::Error surfaced by the underlying driver.

Source

pub fn execute_many<'e, E>( self, executor: E, ) -> impl 'e + Send + Future<Output = BoxStream<'e, Result<DB::QueryResult, Error>>>
where A: 'e, E: 'e + IntoAnnotatedExecutor<'e, DB>, 'q: 'e,

Execute multiple statements separated by ; and return their results as a stream.

execute_many is #[deprecated] in SQLx 0.8 but kept here for parity with the existing executor-side surface. Only Query exposes this method – QueryAs, QueryScalar, and Map have no execute_many upstream.

Source

pub fn map<F, O>( self, f: F, ) -> AnnotatedQuery<Map<'q, DB, impl FnMut(DB::Row) -> Result<O, Error> + Send, A>>
where F: FnMut(DB::Row) -> O + Send, O: Unpin,

Map each row to another type. Mirrors sqlx::query::Query::map and carries the existing annotations forward unchanged onto the resulting AnnotatedQuery<Map<...>>, so with_annotations can be applied either before or after .map().

Source

pub fn try_map<F, O>(self, f: F) -> AnnotatedQuery<Map<'q, DB, F, A>>
where F: FnMut(DB::Row) -> Result<O, Error> + Send, O: Unpin,

Map each row to a Result. Mirrors sqlx::query::Query::try_map and carries the existing annotations forward unchanged.

Source§

impl<'q, DB> AnnotatedQuery<Query<'q, DB, <DB as Database>::Arguments<'q>>>
where DB: Database,

Source

pub fn bind<T>(self, value: T) -> Self
where T: 'q + Encode<'q, DB> + Type<DB>,

Append a parameter binding, forwarding to the inner query. Mirrors the inner builder’s own bind method.

Source§

impl<'q, DB, O, A> AnnotatedQuery<QueryAs<'q, DB, O, A>>
where DB: Database, A: 'q + Send + IntoArguments<'q, DB>, O: Send + Unpin + for<'r> FromRow<'r, DB::Row>,

Source

pub fn with_annotations(self, annotations: QueryAnnotations) -> Self

Replace the wrapper’s annotations. Last-call-wins – any previously set annotations on this wrapper are discarded.

Source

pub fn with_operation( self, operation: impl Into<String>, collection: impl Into<String>, ) -> Self

Shorthand replacement that sets db.operation.name and db.collection.name. Discards any previously set annotations on this wrapper.

Source

pub fn fetch<'e, E>(self, executor: E) -> BoxStream<'e, Result<O, Error>>
where A: 'e, DB: 'e, O: 'e, E: 'e + IntoAnnotatedExecutor<'e, DB>, 'q: 'e,

Stream the resulting rows.

Source

pub fn fetch_many<'e, E>( self, executor: E, ) -> BoxStream<'e, Result<Either<DB::QueryResult, O>, Error>>
where A: 'e, DB: 'e, O: 'e, E: 'e + IntoAnnotatedExecutor<'e, DB>, 'q: 'e,

Stream a mix of QueryResults and rows for multi-statement queries.

fetch_many is #[deprecated] in SQLx 0.8 but kept for parity with the executor-side surface.

Source

pub fn fetch_all<'e, E>( self, executor: E, ) -> impl 'e + Send + Future<Output = Result<Vec<O>, Error>>
where A: 'e, DB: 'e, O: 'e, E: 'e + IntoAnnotatedExecutor<'e, DB>, 'q: 'e,

Collect every row into a Vec.

§Errors

Returns any sqlx::Error surfaced by the underlying driver, including row decoding errors.

Source

pub fn fetch_one<'e, E>( self, executor: E, ) -> impl 'e + Send + Future<Output = Result<O, Error>>
where A: 'e, DB: 'e, O: 'e, E: 'e + IntoAnnotatedExecutor<'e, DB>, 'q: 'e,

Return exactly one row, erroring if none or more than one.

§Errors

Returns sqlx::Error::RowNotFound when the result set is empty, or any other sqlx::Error surfaced by the underlying driver.

Source

pub fn fetch_optional<'e, E>( self, executor: E, ) -> impl 'e + Send + Future<Output = Result<Option<O>, Error>>
where A: 'e, DB: 'e, O: 'e, E: 'e + IntoAnnotatedExecutor<'e, DB>, 'q: 'e,

Return at most one row.

§Errors

Returns any sqlx::Error surfaced by the underlying driver.

Source§

impl<'q, DB, O> AnnotatedQuery<QueryAs<'q, DB, O, <DB as Database>::Arguments<'q>>>
where DB: Database,

Source

pub fn bind<T>(self, value: T) -> Self
where T: 'q + Encode<'q, DB> + Type<DB>,

Append a parameter binding, forwarding to the inner query. Mirrors the inner builder’s own bind method.

Source§

impl<'q, DB, O, A> AnnotatedQuery<QueryScalar<'q, DB, O, A>>
where DB: Database, A: 'q + Send + IntoArguments<'q, DB>, O: Send + Unpin, (O,): Send + Unpin + for<'r> FromRow<'r, DB::Row>,

Source

pub fn with_annotations(self, annotations: QueryAnnotations) -> Self

Replace the wrapper’s annotations. Last-call-wins – any previously set annotations on this wrapper are discarded.

Source

pub fn with_operation( self, operation: impl Into<String>, collection: impl Into<String>, ) -> Self

Shorthand replacement that sets db.operation.name and db.collection.name. Discards any previously set annotations on this wrapper.

Source

pub fn fetch<'e, E>(self, executor: E) -> BoxStream<'e, Result<O, Error>>
where A: 'e, DB: 'e, O: 'e, E: 'e + IntoAnnotatedExecutor<'e, DB>, 'q: 'e,

Stream the resulting rows.

Source

pub fn fetch_many<'e, E>( self, executor: E, ) -> BoxStream<'e, Result<Either<DB::QueryResult, O>, Error>>
where A: 'e, DB: 'e, O: 'e, E: 'e + IntoAnnotatedExecutor<'e, DB>, 'q: 'e,

Stream a mix of QueryResults and rows for multi-statement queries.

fetch_many is #[deprecated] in SQLx 0.8 but kept for parity with the executor-side surface.

Source

pub fn fetch_all<'e, E>( self, executor: E, ) -> impl 'e + Send + Future<Output = Result<Vec<O>, Error>>
where A: 'e, DB: 'e, O: 'e, E: 'e + IntoAnnotatedExecutor<'e, DB>, 'q: 'e,

Collect every row into a Vec.

§Errors

Returns any sqlx::Error surfaced by the underlying driver, including row decoding errors.

Source

pub fn fetch_one<'e, E>( self, executor: E, ) -> impl 'e + Send + Future<Output = Result<O, Error>>
where A: 'e, DB: 'e, O: 'e, E: 'e + IntoAnnotatedExecutor<'e, DB>, 'q: 'e,

Return exactly one row, erroring if none or more than one.

§Errors

Returns sqlx::Error::RowNotFound when the result set is empty, or any other sqlx::Error surfaced by the underlying driver.

Source

pub fn fetch_optional<'e, E>( self, executor: E, ) -> impl 'e + Send + Future<Output = Result<Option<O>, Error>>
where A: 'e, DB: 'e, O: 'e, E: 'e + IntoAnnotatedExecutor<'e, DB>, 'q: 'e,

Return at most one row.

§Errors

Returns any sqlx::Error surfaced by the underlying driver.

Source§

impl<'q, DB, O> AnnotatedQuery<QueryScalar<'q, DB, O, <DB as Database>::Arguments<'q>>>
where DB: Database,

Source

pub fn bind<T>(self, value: T) -> Self
where T: 'q + Encode<'q, DB> + Type<DB>,

Append a parameter binding, forwarding to the inner query. Mirrors the inner builder’s own bind method.

Source§

impl<'q, DB, F, A, O> AnnotatedQuery<Map<'q, DB, F, A>>
where DB: Database, F: FnMut(DB::Row) -> Result<O, Error> + Send, O: Send + Unpin, A: 'q + Send + IntoArguments<'q, DB>,

Source

pub fn with_annotations(self, annotations: QueryAnnotations) -> Self

Replace the wrapper’s annotations. Last-call-wins – any previously set annotations on this wrapper are discarded.

Source

pub fn with_operation( self, operation: impl Into<String>, collection: impl Into<String>, ) -> Self

Shorthand replacement that sets db.operation.name and db.collection.name. Discards any previously set annotations on this wrapper.

Source

pub fn fetch<'e, E>(self, executor: E) -> BoxStream<'e, Result<O, Error>>
where A: 'e, DB: 'e, F: 'e, O: 'e, E: 'e + IntoAnnotatedExecutor<'e, DB>, 'q: 'e,

Stream the resulting rows.

Source

pub fn fetch_many<'e, E>( self, executor: E, ) -> BoxStream<'e, Result<Either<DB::QueryResult, O>, Error>>
where A: 'e, DB: 'e, F: 'e, O: 'e, E: 'e + IntoAnnotatedExecutor<'e, DB>, 'q: 'e,

Stream a mix of QueryResults and rows for multi-statement queries.

fetch_many is #[deprecated] in SQLx 0.8 but kept for parity with the executor-side surface.

Source

pub fn fetch_all<'e, E>( self, executor: E, ) -> impl 'e + Send + Future<Output = Result<Vec<O>, Error>>
where A: 'e, DB: 'e, F: 'e, O: 'e, E: 'e + IntoAnnotatedExecutor<'e, DB>, 'q: 'e,

Collect every row into a Vec.

§Errors

Returns any sqlx::Error surfaced by the underlying driver, including row decoding errors.

Source

pub fn fetch_one<'e, E>( self, executor: E, ) -> impl 'e + Send + Future<Output = Result<O, Error>>
where A: 'e, DB: 'e, F: 'e, O: 'e, E: 'e + IntoAnnotatedExecutor<'e, DB>, 'q: 'e,

Return exactly one row, erroring if none or more than one.

§Errors

Returns sqlx::Error::RowNotFound when the result set is empty, or any other sqlx::Error surfaced by the underlying driver.

Source

pub fn fetch_optional<'e, E>( self, executor: E, ) -> impl 'e + Send + Future<Output = Result<Option<O>, Error>>
where A: 'e, DB: 'e, F: 'e, O: 'e, E: 'e + IntoAnnotatedExecutor<'e, DB>, 'q: 'e,

Return at most one row.

§Errors

Returns any sqlx::Error surfaced by the underlying driver.

Source

pub fn map<G, P>( self, g: G, ) -> AnnotatedQuery<Map<'q, DB, impl FnMut(DB::Row) -> Result<P, Error> + Send, A>>
where G: FnMut(O) -> P + Send, P: Unpin,

Compose a further mapping on top of this annotated map. Mirrors sqlx::query::Map::map (which itself composes via f(row).and_then(&mut g)) and preserves the existing annotations on the wrapper.

Source

pub fn try_map<G, P>( self, g: G, ) -> AnnotatedQuery<Map<'q, DB, impl FnMut(DB::Row) -> Result<P, Error> + Send, A>>
where G: FnMut(O) -> Result<P, Error> + Send, P: Unpin,

Fallible variant of map. Mirrors sqlx::query::Map::try_map and preserves the existing annotations on the wrapper.

Trait Implementations§

Source§

impl<Q> Debug for AnnotatedQuery<Q>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Q> Freeze for AnnotatedQuery<Q>
where Q: Freeze,

§

impl<Q> RefUnwindSafe for AnnotatedQuery<Q>
where Q: RefUnwindSafe,

§

impl<Q> Send for AnnotatedQuery<Q>
where Q: Send,

§

impl<Q> Sync for AnnotatedQuery<Q>
where Q: Sync,

§

impl<Q> Unpin for AnnotatedQuery<Q>
where Q: Unpin,

§

impl<Q> UnsafeUnpin for AnnotatedQuery<Q>
where Q: UnsafeUnpin,

§

impl<Q> UnwindSafe for AnnotatedQuery<Q>
where Q: UnwindSafe,

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Same for T

Source§

type Output = T

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