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>>
impl<'q, DB, A> AnnotatedQuery<Query<'q, DB, A>>
Sourcepub fn with_annotations(self, annotations: QueryAnnotations) -> Self
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.
Sourcepub fn with_operation(
self,
operation: impl Into<String>,
collection: impl Into<String>,
) -> Self
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.
Sourcepub fn fetch<'e, E>(self, executor: E) -> BoxStream<'e, Result<DB::Row, Error>>where
A: 'e,
E: 'e + IntoAnnotatedExecutor<'e, DB>,
'q: 'e,
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.
Sourcepub 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,
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.
Sourcepub async fn fetch_all<'e, E>(self, executor: E) -> Result<Vec<DB::Row>, Error>where
A: 'e,
E: 'e + IntoAnnotatedExecutor<'e, DB>,
'q: 'e,
pub async fn fetch_all<'e, E>(self, executor: E) -> 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.
Sourcepub async fn fetch_one<'e, E>(self, executor: E) -> Result<DB::Row, Error>where
A: 'e,
E: 'e + IntoAnnotatedExecutor<'e, DB>,
'q: 'e,
pub async fn fetch_one<'e, E>(self, executor: E) -> 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.
Sourcepub async fn fetch_optional<'e, E>(
self,
executor: E,
) -> Result<Option<DB::Row>, Error>where
A: 'e,
E: 'e + IntoAnnotatedExecutor<'e, DB>,
'q: 'e,
pub async fn fetch_optional<'e, E>(
self,
executor: E,
) -> Result<Option<DB::Row>, Error>where
A: 'e,
E: 'e + IntoAnnotatedExecutor<'e, DB>,
'q: 'e,
Sourcepub async fn execute<'e, E>(self, executor: E) -> Result<DB::QueryResult, Error>where
A: 'e,
E: 'e + IntoAnnotatedExecutor<'e, DB>,
'q: 'e,
pub async fn execute<'e, E>(self, executor: E) -> 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.
Sourcepub async fn execute_many<'e, E>(
self,
executor: E,
) -> BoxStream<'e, Result<DB::QueryResult, Error>>where
A: 'e,
E: 'e + IntoAnnotatedExecutor<'e, DB>,
'q: 'e,
pub async fn execute_many<'e, E>(
self,
executor: E,
) -> 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.
Sourcepub fn map<F, O>(
self,
f: F,
) -> AnnotatedQuery<Map<'q, DB, impl FnMut(DB::Row) -> Result<O, Error> + Send, A>>
pub fn map<F, O>( self, f: F, ) -> AnnotatedQuery<Map<'q, DB, impl FnMut(DB::Row) -> Result<O, Error> + Send, A>>
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§impl<'q, DB> AnnotatedQuery<Query<'q, DB, <DB as Database>::Arguments<'q>>>where
DB: Database,
impl<'q, DB> AnnotatedQuery<Query<'q, DB, <DB as Database>::Arguments<'q>>>where
DB: Database,
Source§impl<'q, DB, O, A> AnnotatedQuery<QueryAs<'q, DB, O, A>>
impl<'q, DB, O, A> AnnotatedQuery<QueryAs<'q, DB, O, A>>
Sourcepub fn with_annotations(self, annotations: QueryAnnotations) -> Self
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.
Sourcepub fn with_operation(
self,
operation: impl Into<String>,
collection: impl Into<String>,
) -> Self
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.
Sourcepub 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,
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.
Sourcepub 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,
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.
Sourcepub async fn fetch_all<'e, E>(self, executor: E) -> Result<Vec<O>, Error>where
A: 'e,
DB: 'e,
O: 'e,
E: 'e + IntoAnnotatedExecutor<'e, DB>,
'q: 'e,
pub async fn fetch_all<'e, E>(self, executor: E) -> 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.
Sourcepub async fn fetch_one<'e, E>(self, executor: E) -> Result<O, Error>where
A: 'e,
DB: 'e,
O: 'e,
E: 'e + IntoAnnotatedExecutor<'e, DB>,
'q: 'e,
pub async fn fetch_one<'e, E>(self, executor: E) -> 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.
Sourcepub async fn fetch_optional<'e, E>(
self,
executor: E,
) -> Result<Option<O>, Error>where
A: 'e,
DB: 'e,
O: 'e,
E: 'e + IntoAnnotatedExecutor<'e, DB>,
'q: 'e,
pub async fn fetch_optional<'e, E>(
self,
executor: E,
) -> Result<Option<O>, Error>where
A: 'e,
DB: 'e,
O: 'e,
E: 'e + IntoAnnotatedExecutor<'e, DB>,
'q: 'e,
Source§impl<'q, DB, O> AnnotatedQuery<QueryAs<'q, DB, O, <DB as Database>::Arguments<'q>>>where
DB: Database,
impl<'q, DB, O> AnnotatedQuery<QueryAs<'q, DB, O, <DB as Database>::Arguments<'q>>>where
DB: Database,
Source§impl<'q, DB, O, A> AnnotatedQuery<QueryScalar<'q, DB, O, A>>
impl<'q, DB, O, A> AnnotatedQuery<QueryScalar<'q, DB, O, A>>
Sourcepub fn with_annotations(self, annotations: QueryAnnotations) -> Self
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.
Sourcepub fn with_operation(
self,
operation: impl Into<String>,
collection: impl Into<String>,
) -> Self
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.
Sourcepub 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,
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.
Sourcepub 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,
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.
Sourcepub async fn fetch_all<'e, E>(self, executor: E) -> Result<Vec<O>, Error>where
A: 'e,
DB: 'e,
O: 'e,
E: 'e + IntoAnnotatedExecutor<'e, DB>,
'q: 'e,
pub async fn fetch_all<'e, E>(self, executor: E) -> 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.
Sourcepub async fn fetch_one<'e, E>(self, executor: E) -> Result<O, Error>where
A: 'e,
DB: 'e,
O: 'e,
E: 'e + IntoAnnotatedExecutor<'e, DB>,
'q: 'e,
pub async fn fetch_one<'e, E>(self, executor: E) -> 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.
Sourcepub async fn fetch_optional<'e, E>(
self,
executor: E,
) -> Result<Option<O>, Error>where
A: 'e,
DB: 'e,
O: 'e,
E: 'e + IntoAnnotatedExecutor<'e, DB>,
'q: 'e,
pub async fn fetch_optional<'e, E>(
self,
executor: E,
) -> Result<Option<O>, Error>where
A: 'e,
DB: 'e,
O: 'e,
E: 'e + IntoAnnotatedExecutor<'e, DB>,
'q: 'e,
Source§impl<'q, DB, O> AnnotatedQuery<QueryScalar<'q, DB, O, <DB as Database>::Arguments<'q>>>where
DB: Database,
impl<'q, DB, O> AnnotatedQuery<QueryScalar<'q, DB, O, <DB as Database>::Arguments<'q>>>where
DB: Database,
Source§impl<'q, DB, F, A, O> AnnotatedQuery<Map<'q, DB, F, A>>
impl<'q, DB, F, A, O> AnnotatedQuery<Map<'q, DB, F, A>>
Sourcepub fn with_annotations(self, annotations: QueryAnnotations) -> Self
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.
Sourcepub fn with_operation(
self,
operation: impl Into<String>,
collection: impl Into<String>,
) -> Self
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.
Sourcepub 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,
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.
Sourcepub 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,
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.
Sourcepub async fn fetch_all<'e, E>(self, executor: E) -> Result<Vec<O>, Error>where
A: 'e,
DB: 'e,
F: 'e,
O: 'e,
E: 'e + IntoAnnotatedExecutor<'e, DB>,
'q: 'e,
pub async fn fetch_all<'e, E>(self, executor: E) -> 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.
Sourcepub async fn fetch_one<'e, E>(self, executor: E) -> Result<O, Error>where
A: 'e,
DB: 'e,
F: 'e,
O: 'e,
E: 'e + IntoAnnotatedExecutor<'e, DB>,
'q: 'e,
pub async fn fetch_one<'e, E>(self, executor: E) -> 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.
Sourcepub async fn fetch_optional<'e, E>(
self,
executor: E,
) -> Result<Option<O>, Error>where
A: 'e,
DB: 'e,
F: 'e,
O: 'e,
E: 'e + IntoAnnotatedExecutor<'e, DB>,
'q: 'e,
pub async fn fetch_optional<'e, E>(
self,
executor: E,
) -> Result<Option<O>, Error>where
A: 'e,
DB: 'e,
F: 'e,
O: 'e,
E: 'e + IntoAnnotatedExecutor<'e, DB>,
'q: 'e,
Sourcepub fn map<G, P>(
self,
g: G,
) -> AnnotatedQuery<Map<'q, DB, impl FnMut(DB::Row) -> Result<P, Error> + Send, A>>
pub fn map<G, P>( self, g: G, ) -> AnnotatedQuery<Map<'q, DB, impl FnMut(DB::Row) -> Result<P, Error> + Send, A>>
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.
Trait Implementations§
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> 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
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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>
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>
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