sparkling/query

Types

Order by clause with direction.

pub type OrderBy {
  OrderBy(expr: expr.Expr, direction: OrderDirection)
}

Constructors

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

Values

pub fn distinct(query: Query) -> Query

Set DISTINCT flag.

pub fn from(query: Query, table: String) -> Query

Set the FROM clause (table name).

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 limit(query: Query, count: Int) -> Query

Set the LIMIT clause.

pub fn new() -> Query

Create a new empty query.

pub fn offset(query: Query, count: Int) -> Query

Set the OFFSET clause.

pub fn order_by(
  query: Query,
  expr: expr.Expr,
  direction: OrderDirection,
) -> Query

Add an ORDER BY clause.

pub fn order_by_asc(query: Query, expr: expr.Expr) -> Query

Add an ORDER BY ASC clause.

pub fn order_by_desc(query: Query, expr: expr.Expr) -> Query

Add an ORDER BY DESC 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.

pub fn where(query: Query, condition: expr.Expr) -> Query

Add a WHERE condition (AND-ed with existing conditions).

pub fn where_all(
  query: Query,
  conditions: List(expr.Expr),
) -> Query

Add multiple WHERE conditions (AND-ed with existing conditions).

Search Document