module Clear::SQL::Query::Where
Overview
Feature WHERE clause building.
each call to where method stack where clause.
Theses clauses are then combined together using the AND
operator.
Therefore, query.where("a").where("b")
will return a AND b
Direct including types
- Clear::SQL::DeleteQuery
- Clear::SQL::Query::OnConflict::OnConflictWhereClause
- Clear::SQL::SelectBuilder
- Clear::SQL::UpdateQuery
Defined in:
clear/sql/query/where.crInstance Method Summary
-
#clear_wheres
Clear all the where clauses and return
self
-
#or_where(node : Clear::Expression::Node)
Build SQL
#or_where
condition using a Clear::Expression::Node`crystal query.or_where(Clear::Expression::Node::InArray.new("id", ['1', '2', '3', '4'])) # Note: in this example, InArray node use unsafe strings
` If useful for moving a where clause from a request to another one:
`crystal query1.or_where { a == b } # WHERE a = b
`
` query2.or_where(query1.wheres[0]) # WHERE a = b
`
- #or_where(__template : String, *__args)
- #or_where(__template : String, **__named_tuple)
-
#or_where(&)
Build SQL
#where
condition using the Expression engine. -
#where(node : Clear::Expression::Node)
Build SQL
#where
condition using a Clear::Expression::Node`crystal query.where(Clear::Expression::Node::InArray.new("id", ['1', '2', '3', '4'])) # Note: in this example, InArray node use unsafe strings
` If useful for moving a where clause from a request to another one:
`crystal query1.where { a == b } # WHERE a = b
`
` query2.where(query1.wheres[0]) # WHERE a = b
`
-
#where(&)
Build SQL
#where
condition using the Expression engine. -
#where(__conditions : NamedTuple | Hash(String, Clear::SQL::Any))
Build SQL
#where
condition using a NamedTuple. -
#where(__template : String, *__args)
Build SQL
#where
condition using a template string and interpolating?
characters with parameters given in a tuple or array. -
#where(__template : String, **__tuple)
Build SQL
#where
interpolating:keyword
with the NamedTuple passed in argument. - #where(**tuple)
Instance Method Detail
Build SQL #or_where
condition using a Clear::Expression::Node
query.or_where(Clear::Expression::Node::InArray.new("id", ['1', '2', '3', '4']))
# Note: in this example, InArray node use unsafe strings
If useful for moving a where clause from a request to another one:
query1.or_where { a == b } # WHERE a = b
query2.or_where(query1.wheres[0]) # WHERE a = b
Build SQL #where
condition using the Expression engine.
query.or_where { id == 1 }
Build SQL #where
condition using a Clear::Expression::Node
query.where(Clear::Expression::Node::InArray.new("id", ['1', '2', '3', '4']))
# Note: in this example, InArray node use unsafe strings
If useful for moving a where clause from a request to another one:
query1.where { a == b } # WHERE a = b
query2.where(query1.wheres[0]) # WHERE a = b
Build SQL #where
condition using a NamedTuple.
this will use:
- the
=
operator if compared with a literal
query.where({keyword: "hello"}) # WHERE keyword = 'hello'
- the
IN
operator if compared with an array:
query.where({x: [1, 2]}) # WHERE x in (1, 2)
- the
>=
and<=
|<
if compared with a range:
query.where({x: (1..4)}) # WHERE x >= 1 AND x <= 4
query.where({x: (1...4)}) # WHERE x >= 1 AND x < 4
- You also can put another select query as argument:
query.where({x: another_select}) # WHERE x IN (SELECT ... )
Build SQL #where
condition using a template string and
interpolating ?
characters with parameters given in a tuple or array.
where("x = ? OR y = ?", 1, "l'eau") # WHERE x = 1 OR y = 'l''eau'
Raise error if there's not enough parameters to cover all the ?
placeholders