#[non_exhaustive]pub struct BuiltQuery {
pub sql: String,
pub params: Params,
pub cacheable: bool,
}Expand description
Rendered SQL plus its bind parameters.
Builders expose convenience fetch_* methods that call build() each time.
Keep a BuiltQuery when you want to inspect SQL, log the generated shape,
or execute the same validated query more than once with the same binds.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.sql: StringRendered Postgres SQL using $N placeholders.
params: ParamsBind parameters in placeholder order.
cacheable: boolWhether this query is safe to reuse as a stable prepared statement shape.
rqb passes this to sqlx .persistent(cacheable). SQLx keeps a bounded
per-connection prepared-statement cache for Postgres, with a default
capacity of 100 entries. Raw SQL fragments make the query non-cacheable
because rqb cannot prove that their text is a stable statement shape.
High-cardinality typed query shapes, such as many different IN list
lengths or optional-filter combinations, stay memory-bounded by sqlx’s
LRU cache but can still churn prepared statements. Tune sqlx with
PgConnectOptions::statement_cache_capacity or the
statement-cache-capacity URL parameter when an application needs a
different cache size.
Implementations§
Source§impl BuiltQuery
impl BuiltQuery
Sourcepub fn arguments(&self) -> Result<PgArguments>
pub fn arguments(&self) -> Result<PgArguments>
Converts stored parameters into sqlx Postgres arguments for one execution.
sqlx argument buffers are consumed by execution, so each execute/fetch
path creates a fresh PgArguments value from the stored params.
Sourcepub fn summary(&self) -> String
pub fn summary(&self) -> String
Returns debug-friendly query output.
The output includes pretty-printed rendered SQL, bind parameter count, Rust type names, and cacheability. It never interpolates bind values into SQL.
Sourcepub fn pretty_sql(&self) -> String
pub fn pretty_sql(&self) -> String
Returns only the formatted SQL text for human-readable logs.
This does not change BuiltQuery::sql, which remains the exact SQL
text used for execution.
Source§impl BuiltQuery
impl BuiltQuery
Sourcepub async fn execute<'e>(&self, executor: impl PgExecutor<'e>) -> Result<u64>
pub async fn execute<'e>(&self, executor: impl PgExecutor<'e>) -> Result<u64>
Executes the query and returns affected row count.
Sourcepub async fn fetch_all<'e>(
&self,
executor: impl PgExecutor<'e>,
) -> Result<Vec<PgRow>>
pub async fn fetch_all<'e>( &self, executor: impl PgExecutor<'e>, ) -> Result<Vec<PgRow>>
Fetches all rows as raw sqlx PgRow values.
Sourcepub fn fetch_stream<'q, 'e>(
&'q self,
executor: impl PgExecutor<'e> + 'q,
) -> Result<BoxStream<'q, Result<PgRow>>>where
'e: 'q,
pub fn fetch_stream<'q, 'e>(
&'q self,
executor: impl PgExecutor<'e> + 'q,
) -> Result<BoxStream<'q, Result<PgRow>>>where
'e: 'q,
Streams raw sqlx PgRow values.
The returned stream borrows this BuiltQuery, so keep the built query
value alive until the stream is fully consumed.
Sourcepub fn fetch_stream_pool(
self,
pool: PgPool,
) -> Result<BoxStream<'static, Result<PgRow>>>
pub fn fetch_stream_pool( self, pool: PgPool, ) -> Result<BoxStream<'static, Result<PgRow>>>
Streams raw sqlx PgRow values from an owned pool-backed query.
The returned stream owns this built query and a cloneable PgPool
handle, so it can outlive the call frame that created it.
Sourcepub async fn fetch_one<'e>(
&self,
executor: impl PgExecutor<'e>,
) -> Result<PgRow>
pub async fn fetch_one<'e>( &self, executor: impl PgExecutor<'e>, ) -> Result<PgRow>
Fetches exactly one raw sqlx PgRow.
Sourcepub async fn fetch_optional<'e>(
&self,
executor: impl PgExecutor<'e>,
) -> Result<Option<PgRow>>
pub async fn fetch_optional<'e>( &self, executor: impl PgExecutor<'e>, ) -> Result<Option<PgRow>>
Fetches zero or one raw sqlx PgRow.
Sourcepub async fn fetch_all_as<'e, T>(
&self,
executor: impl PgExecutor<'e>,
) -> Result<Vec<T>>
pub async fn fetch_all_as<'e, T>( &self, executor: impl PgExecutor<'e>, ) -> Result<Vec<T>>
Fetches all rows into a sqlx::FromRow type.
Sourcepub fn fetch_stream_as<'q, 'e, T>(
&'q self,
executor: impl PgExecutor<'e> + 'q,
) -> Result<BoxStream<'q, Result<T>>>
pub fn fetch_stream_as<'q, 'e, T>( &'q self, executor: impl PgExecutor<'e> + 'q, ) -> Result<BoxStream<'q, Result<T>>>
Streams rows into a sqlx::FromRow type.
Streaming avoids materializing large exports in memory. Keep the
BuiltQuery value alive while consuming the stream.
Sourcepub fn fetch_stream_pool_as<T>(
self,
pool: PgPool,
) -> Result<BoxStream<'static, Result<T>>>
pub fn fetch_stream_pool_as<T>( self, pool: PgPool, ) -> Result<BoxStream<'static, Result<T>>>
Streams rows into a sqlx::FromRow type from an owned pool-backed query.
The returned stream owns this built query and a cloneable PgPool
handle, so it can outlive the call frame that created it.
Sourcepub async fn fetch_one_as<'e, T>(
&self,
executor: impl PgExecutor<'e>,
) -> Result<T>
pub async fn fetch_one_as<'e, T>( &self, executor: impl PgExecutor<'e>, ) -> Result<T>
Fetches exactly one row into a sqlx::FromRow type.
Sourcepub async fn fetch_optional_as<'e, T>(
&self,
executor: impl PgExecutor<'e>,
) -> Result<Option<T>>
pub async fn fetch_optional_as<'e, T>( &self, executor: impl PgExecutor<'e>, ) -> Result<Option<T>>
Fetches zero or one row into a sqlx::FromRow type.
Sourcepub async fn fetch_scalar<'e, T>(
&self,
executor: impl PgExecutor<'e>,
) -> Result<Vec<T>>where
T: ScalarValue,
pub async fn fetch_scalar<'e, T>(
&self,
executor: impl PgExecutor<'e>,
) -> Result<Vec<T>>where
T: ScalarValue,
Fetches all rows as a single decoded scalar column.
Sourcepub fn fetch_stream_scalar<'q, 'e, T>(
&'q self,
executor: impl PgExecutor<'e> + 'q,
) -> Result<BoxStream<'q, Result<T>>>where
T: ScalarValue + 'q,
'e: 'q,
pub fn fetch_stream_scalar<'q, 'e, T>(
&'q self,
executor: impl PgExecutor<'e> + 'q,
) -> Result<BoxStream<'q, Result<T>>>where
T: ScalarValue + 'q,
'e: 'q,
Streams rows as a single decoded scalar column.
Keep the BuiltQuery value alive while consuming the stream.
Sourcepub fn fetch_stream_pool_scalar<T>(
self,
pool: PgPool,
) -> Result<BoxStream<'static, Result<T>>>where
T: ScalarValue + 'static,
pub fn fetch_stream_pool_scalar<T>(
self,
pool: PgPool,
) -> Result<BoxStream<'static, Result<T>>>where
T: ScalarValue + 'static,
Streams rows as a single decoded scalar column from an owned pool-backed query.
The returned stream owns this built query and a cloneable PgPool
handle, so it can outlive the call frame that created it.
Sourcepub async fn fetch_one_scalar<'e, T>(
&self,
executor: impl PgExecutor<'e>,
) -> Result<T>where
T: ScalarValue,
pub async fn fetch_one_scalar<'e, T>(
&self,
executor: impl PgExecutor<'e>,
) -> Result<T>where
T: ScalarValue,
Fetches exactly one decoded scalar value.
Sourcepub async fn fetch_optional_scalar<'e, T>(
&self,
executor: impl PgExecutor<'e>,
) -> Result<Option<T>>where
T: ScalarValue,
pub async fn fetch_optional_scalar<'e, T>(
&self,
executor: impl PgExecutor<'e>,
) -> Result<Option<T>>where
T: ScalarValue,
Fetches zero or one decoded scalar value.
Trait Implementations§
Source§impl Clone for BuiltQuery
impl Clone for BuiltQuery
Source§fn clone(&self) -> BuiltQuery
fn clone(&self) -> BuiltQuery
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for BuiltQuery
impl !UnwindSafe for BuiltQuery
impl Freeze for BuiltQuery
impl Send for BuiltQuery
impl Sync for BuiltQuery
impl Unpin for BuiltQuery
impl UnsafeUnpin for BuiltQuery
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> 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> 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