pub struct Subquery<T: Model, V> { /* private fields */ }Expand description
Typed scalar subquery — lowers to (SELECT <col> FROM <table> WHERE <cond>) when emitted.
T pins the source model (so the emitter knows which table to
SELECT from) and V pins the column’s Rust type (so the scalar
returned by the subquery slots into Expr<V> positions without an
explicit cast). Both are phantom-typed; the node itself carries only
the untyped [SubqueryNode] payload.
#[must_use] — a dropped Subquery is usually a mistake; the user
likely meant to feed it to .as_expr() and thence to
crate::query::QuerySet::filter_expr / an arithmetic composition.
Construction: Subquery::new takes the source queryset and the
projected column. No other public constructor — the SubqueryNode
inside is crate-private so downstream code cannot fabricate a
subquery with a mismatched column / type pair.
Implementations§
Source§impl<T: Model, V> Subquery<T, V>
impl<T: Model, V> Subquery<T, V>
Sourcepub fn new<S>(qs: QuerySet<T>, column: S) -> Selfwhere
S: IntoSqlField<T, V>,
pub fn new<S>(qs: QuerySet<T>, column: S) -> Selfwhere
S: IntoSqlField<T, V>,
Build a scalar subquery from a source queryset and the column to
project.
The qs parameter supplies the FROM <table> source and the
correlated WHERE predicate; the column parameter picks which
scalar the subquery returns. T on both arguments is the same
model, so the compiler rejects a column ref taken from a
different model’s Fields handle.
§How the WHERE clause flows
qs.condition is cloned verbatim into the
[SubqueryNode::where_clause] slot — every lookup op the
caller composed via filter / filter_expr is preserved. The
clone is structural (the condition tree is shallow Vec / Box
/ enum variants); typical correlated-subquery call sites build
the queryset fresh, so there is nothing to share-ownership with.
Condition::True (the “no filter” identity) is stored as
Some(True) and the emitter renders it as WHERE TRUE. This
matches the existing push_where shim’s behaviour — a vacuous
predicate is rare in correlated subqueries, so the emission
overhead is not worth a special case here.
§What this ignores about qs
A queryset carries ordering, limit/offset, distinct mode, and
prefetch / select_related registrations. The subquery emitter
consumes only the table name and condition tree; ordering and
pagination are ignored because Postgres’ scalar-subquery context
does not use them (a scalar subquery must return a single value;
ORDER BY ... LIMIT 1 would be the usual way to force that but
is out of scope for Task 5). Callers who need a deterministic
scalar from a multi-row source should use ctx.raw_scalar
until extends this surface.
PR3: accepts both legacy FieldRef<T, V> and the post-flip root
accessor return type DjogiField<T, V> through the sealed
IntoSqlField bridge.
Subquery SELECT <col> is a SQL-only emission boundary — the
projected column metadata flows through unchanged.
Sourcepub fn as_expr(self) -> Expr<V>
pub fn as_expr(self) -> Expr<V>
Promote this subquery to a typed Expr<V> for use in
filter_expr, set_expr, or any other expression-IR consumer.
The phantom V on Subquery<T, V> projects directly onto the
resulting Expr<V> — so a subquery that selects a HeerId
column produces an Expr<HeerId> that can .eq another
Expr<HeerId>, and nothing else. Type discipline all the way
through.
Auto Trait Implementations§
impl<T, V> !RefUnwindSafe for Subquery<T, V>
impl<T, V> !UnwindSafe for Subquery<T, V>
impl<T, V> Freeze for Subquery<T, V>
impl<T, V> Send for Subquery<T, V>
impl<T, V> Sync for Subquery<T, V>
impl<T, V> Unpin for Subquery<T, V>
impl<T, V> UnsafeUnpin for Subquery<T, V>
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> 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<V> IntoPortableFieldValue<Option<V>> for V
impl<V> IntoPortableFieldValue<Option<V>> for V
Source§fn into_portable_field_value(self) -> Option<V>
fn into_portable_field_value(self) -> Option<V>
self into the field’s declared portable value type.
The returned value flows into Sassi’s Field<M, FieldValue>::eq /
.gt / .in_ / etc. as the right-hand-side operand. Implementors
must produce a value whose PartialEq / PartialOrd / Hash
behaviour matches the on-disk column ordering — otherwise Punnu and
the database row will disagree at evaluation time.Source§impl<V> IntoPortableFieldValue<Tracked<V>> for V
impl<V> IntoPortableFieldValue<Tracked<V>> for V
Source§fn into_portable_field_value(self) -> Tracked<V>
fn into_portable_field_value(self) -> Tracked<V>
self into the field’s declared portable value type.
The returned value flows into Sassi’s Field<M, FieldValue>::eq /
.gt / .in_ / etc. as the right-hand-side operand. Implementors
must produce a value whose PartialEq / PartialOrd / Hash
behaviour matches the on-disk column ordering — otherwise Punnu and
the database row will disagree at evaluation time.Source§impl<V> IntoPortableFieldValue<V> for V
impl<V> IntoPortableFieldValue<V> for V
Source§fn into_portable_field_value(self) -> V
fn into_portable_field_value(self) -> V
self into the field’s declared portable value type.
The returned value flows into Sassi’s Field<M, FieldValue>::eq /
.gt / .in_ / etc. as the right-hand-side operand. Implementors
must produce a value whose PartialEq / PartialOrd / Hash
behaviour matches the on-disk column ordering — otherwise Punnu and
the database row will disagree at evaluation time.Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);