drizzle_core/builder.rs
1/// Marker trait for executable builder states.
2///
3/// This is an extension point for driver crates to opt in builder state
4/// markers that represent complete, executable queries (for example, to
5/// enable set operations or prepared statements on those states).
6pub trait ExecutableState {}
7
8#[derive(Debug, Clone)]
9pub struct BuilderInit;
10
11impl ExecutableState for BuilderInit {}
12
13// =============================================================================
14// Capability marker traits for typestate method gating
15// =============================================================================
16// These allow a single generic impl block per method instead of duplicating
17// across every state that supports it.
18//
19// Used directly by the inner `SelectBuilder` impls in driver crates.
20// Wrapper builders (`DrizzleBuilder`, `TransactionBuilder`) use a declarative
21// macro to stamp out per-state impls instead, because Rust's inherent impl
22// overlap rules prevent trait-gated generics when other builder types
23// (insert/update/delete) define methods with the same name.
24
25/// States where `.where()` is available.
26pub trait WhereAllowed {}
27
28/// States where `.group_by()` is available.
29pub trait GroupByAllowed {}
30
31/// States where `.order_by()` is available.
32pub trait OrderByAllowed {}
33
34/// States where `.limit()` is available.
35pub trait LimitAllowed {}
36
37/// States where `.offset()` is available.
38pub trait OffsetAllowed {}
39
40/// States where `.join()` and variant joins are available.
41pub trait JoinAllowed {}
42
43/// States where `.having()` is available (requires GROUP BY).
44pub trait HavingAllowed {}
45
46/// States where GROUP BY has been applied (allows mixed agg/scalar selects).
47#[diagnostic::on_unimplemented(
48 message = "SELECT mixes aggregate and non-aggregate expressions without GROUP BY",
49 label = "add .group_by(...) before executing this query"
50)]
51pub trait GroupByApplied {}