Expand description
Query builders used to express SELECT, INSERT, UPDATE, and DELETE
statements against an Entity.
Most queries originate from an entity:
â
cake::Entity::find() // -> Select<cake::Entity>
cake::Entity::insert(am) // -> Insert<cake::ActiveModel>
cake::Entity::update(am) // -> UpdateOne<cake::ActiveModel>
cake::Entity::delete(am) // -> DeleteOne<cake::Entity>The builders implement composable traits â QueryFilter,
QuerySelect, QueryOrder, QueryTrait â for adding WHERE
clauses, joins, ordering, and column projections. Once composed, hand the
query to a ConnectionTrait via .one(db), .all(db), .exec(db),
.stream(db), etc.
For raw SQL, use Statement together with the raw_sql!
macro.
Re-exports§
pub use crate::ConnectionTrait;pub use crate::CursorTrait;pub use crate::InsertResult;pub use crate::PaginatorTrait;pub use crate::SelectExt;pub use crate::Statement;pub use crate::TransactionTrait;pub use crate::UpdateResult;pub use crate::StreamTrait;stream
Macros§
- debug_
query - Helper to get a raw SQL string from an object that impl
QueryTrait. - debug_
query_ stmt - Helper to get a
Statementfrom an object that implQueryTrait.
Structs§
- Condition
- Represents the value of an
Condition::anyorCondition::all: a set of disjunctive or conjunctive conditions. - Debug
Query - Glue type used by the
debug_query!/debug_query_stmt!macros to render a query for a specific backend or connection. Most code should use those macros rather than naming this type directly. - Delete
- Type-level entry point for
DELETEbuilders, e.g.Delete::one(model)andDelete::many(Entity). You normally callEntityTrait::delete/delete_manyinstead. - Delete
Many - Multi-row
DELETEbuilder, returned byEntityTrait::delete_many. Add.filter(...)to scope which rows are deleted. - Delete
One - A request to delete an
ActiveModel. - DynIden
- A prepared (quoted) identifier string.
- Insert
- Single-row
INSERTbuilder, returned byEntityTrait::insert. Chain.on_conflict(...)or.on_empty_returning(...)then dispatch with.exec(db)or.exec_with_returning(db). - Insert
Many - Multi-row
INSERTbuilder, returned byEntityTrait::insert_many. Adds.exec_with_returning_manyand.exec_with_returning_keysfor batch inserts that need the resulting rows or primary keys. - Select
- A
SELECTquery against entityE. Returned byEntityTrait::find; chain filters, joins, ordering, and projections onto it, then run it on aConnectionTraitwith.one(db)/.all(db)/.stream(db)/.paginate(db, n). - SelectA
- Iden used to alias one side of a multi-table
SELECT, so column names from each joined table can be prefixed without clashing (e.g.select_a_id,select_b_id). - SelectB
- Iden used to alias one side of a multi-table
SELECT, so column names from each joined table can be prefixed without clashing (e.g.select_a_id,select_b_id). - SelectC
- Iden used to alias one side of a multi-table
SELECT, so column names from each joined table can be prefixed without clashing (e.g.select_a_id,select_b_id). - Select
Five - Five-way join select.
- Select
Four - Four-way join select.
- Select
Four Many - Like
SelectFour, but results are consolidated under the left model. - Select
Six - Six-way join select.
- Select
Three - Three-way join select, yielding
(E::Model, Option<F::Model>, Option<G::Model>). TheTOPparameter is the joinTopology. - Select
Three Many - Like
SelectThree, but results are consolidated under the left model:(E::Model, Vec<F::Model>, Vec<G::Model>). - Select
Two - A
SELECTjoining two entities, yielding(E::Model, Option<F::Model>)per row â the right side isNonefor outer-join rows with no match. Returned bySelect::find_also_relatedand similar helpers. - Select
TwoMany - A
SELECTjoining two entities, with results grouped into(E::Model, Vec<F::Model>)per left model. Returned bySelect::find_with_related. - Select
TwoRequired - A
SELECTjoining two entities where both sides are required, yielding(E::Model, F::Model)per row (noOption). - Topology
Chain - Chain join: each entity joined to the previous one in sequence.
- Topology
Star - Star join: a centre entity joined separately to each of the others.
- TryInsert
- Wrapper of
Insert/InsertMany, treats âno row inserted/id returnedâ as a normal outcome. - Update
- Type-level entry point for
UPDATEbuilders, e.g.Update::one(model)andUpdate::many(Entity). You normally callEntityTrait::update/update_manyinstead. - Update
Many - Multi-row
UPDATEbuilder, returned byEntityTrait::update_many. Add.col_expr(...)to set columns and.filter(...)to scope which rows are updated. - Update
One - A request to update an
ActiveModel. - Validated
Delete One - A validated
DeleteOnerequest, where the primary key is set and itâs possible to generate the right SQL condition. - Validated
Update One - A validated
UpdateOnerequest, where the primary key is set and itâs possible to generate the right SQL condition. - Values
Enums§
Traits§
- Column
AsExpr - Like
IntoSimpleExprbut applies SeaORMâs enum-to-text cast forActiveEnumcolumns appearing in a SELECT list. - Conditional
Statement - Entity
OrSelect - Either an
Entityor aSelect<Entity>; accepted byLoaderTraitso you can pass the entity directly when no filtering is needed, or a pre-filteredSelectwhen it is. - Expr
Trait - âOperatorâ methods for building expressions.
- Into
Simple Expr - Conversion into a
SimpleExpr. Implemented for entity columns so they can be used anywhere asea_queryexpression is expected. - Loader
Trait - Batch-load related entities for a slice of parent models, avoiding the N+1 query problem.
- Ordered
Statement - Query
Filter - Methods for adding
WHERE/AND/ORconditions to a query. The entry point most code uses isfilter. - Query
Order - Methods for adding
ORDER BYclauses to a query. - Query
Select - Methods for narrowing a queryâs projection, joining other tables, and
adding
GROUP BY/HAVINGclauses. Implemented forSelect,SelectTwo,SelectTwoMany, and the higher-arity selects. - Query
Trait - Common operations on a SeaORM query builder: borrow the underlying
sea_querystatement, build it into a backend-specificStatement, or apply optional modifications viaapply_if. - Topology
- Marker trait describing how 3+ tables are joined: from one centre entity
to several siblings (
TopologyStar) or in a sequential chain (TopologyChain).