Skip to main content

drizzle_core/
builder.rs

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