sparkling/query
Types
Order by clause with direction.
pub type OrderBy {
OrderBy(expr: expr.Expr, direction: OrderDirection)
}
Constructors
-
OrderBy(expr: expr.Expr, direction: OrderDirection)
Sort direction for ORDER BY.
pub type OrderDirection {
Asc
Desc
}
Constructors
-
Asc -
Desc
Represents a SELECT query with various clauses. All fields are optional to support incremental query building.
pub type Query {
Query(
from: option.Option(String),
select: List(expr.Expr),
where: List(expr.Expr),
group_by: List(expr.Expr),
having: List(expr.Expr),
order_by: List(OrderBy),
limit: option.Option(Int),
offset: option.Option(Int),
distinct: Bool,
)
}
Constructors
-
Query( from: option.Option(String), select: List(expr.Expr), where: List(expr.Expr), group_by: List(expr.Expr), having: List(expr.Expr), order_by: List(OrderBy), limit: option.Option(Int), offset: option.Option(Int), distinct: Bool, )
Values
pub fn group_by(query: Query, exprs: List(expr.Expr)) -> Query
Add expressions to the GROUP BY clause.
pub fn having(query: Query, condition: expr.Expr) -> Query
Add a HAVING condition (AND-ed with existing HAVING conditions).
pub fn order_by(
query: Query,
expr: expr.Expr,
direction: OrderDirection,
) -> Query
Add an ORDER BY clause.
pub fn select(query: Query, exprs: List(expr.Expr)) -> Query
Add expressions to the SELECT clause. Can be called multiple times to add more expressions.
pub fn select_expr(query: Query, expr: expr.Expr) -> Query
Add a single expression to the SELECT clause.
pub fn to_sql(query: Query) -> Result(String, String)
Convert a Query to a SQL string for ClickHouse. Validates that required clauses (FROM, SELECT) are present.