module Clear::SQL::Query::Having
Direct including types
Defined in:
clear/sql/query/having.crInstance Method Summary
-
#clear_havings
Clear all the having clauses and return
self
-
#having(node : Clear::Expression::Node)
Build SQL
#having
condition using a Clear::Expression::Node -
#having(&)
Build SQL
#having
condition using the Expression engine. -
#having(conditions : NamedTuple | Hash(String, Clear::SQL::Any))
Build SQL
#having
condition using a NamedTuple. -
#having(template : String, *args)
Build SQL
#having
condition using a template string and interpolating?
characters with parameters given in a tuple or array. -
#having(template : String, **tuple)
Build SQL
#having
interpolating:keyword
with the NamedTuple passed in argument. - #having(**tuple)
-
#or_having(node : Clear::Expression::Node)
Build SQL
#or_having
condition using a Clear::Expression::Node - #or_having(template : String, *args)
- #or_having(template : String, **named_tuple)
-
#or_having(&)
Build SQL
#having
condition using the Expression engine.
Instance Method Detail
Build SQL #having
condition using a Clear::Expression::Node
query.having(Clear::Expression::Node::InArray.new("id", ['1', '2', '3', '4']))
# Note: in this example, InArray node use unsafe strings
If useful for moving a having clause from a request to another one:
query1.having { a == b } # having a = b
query2.having(query1.havings[0]) # HAVING a = b
Build SQL #having
condition using a NamedTuple.
this will use:
- the
=
operator if compared with a literal
query.having({keyword: "hello"}) # having keyword = 'hello'
- the
IN
operator if compared with an array:
query.having({x: [1, 2]}) # having x in (1, 2)
- the
>=
and<=
|<
if compared with a range:
query.having({x: (1..4)}) # having x >= 1 AND x <= 4
query.having({x: (1...4)}) # having x >= 1 AND x < 4
- You also can put another select query as argument:
query.having({x: another_select}) # having x IN (SELECT ... )
Build SQL #having
condition using a template string and
interpolating ?
characters with parameters given in a tuple or array.
having("x = ? OR y = ?", 1, "l'eau") # having x = 1 OR y = 'l''eau'
Raise error if there's not enough parameters to cover all the ?
placeholders
Build SQL #having
interpolating :keyword
with the NamedTuple passed in argument.
having("id = :id OR date >= :start", id: 1, start: 1.day.ago)
# having id = 1 AND date >= '201x-xx-xx ...'
Build SQL #or_having
condition using a Clear::Expression::Node
query.or_having(Clear::Expression::Node::InArray.new("id", ['1', '2', '3', '4']))
# Note: in this example, InArray node use unsafe strings
If useful for moving a having clause from a request to another one:
query1.or_having { a == b } # having a = b
query2.or_having(query1.havings[0]) # having a = b