/
where.jl
51 lines (39 loc) · 1.14 KB
/
where.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# WHERE clause.
mutable struct WhereClause <: AbstractSQLClause
over::Union{SQLClause, Nothing}
condition::SQLClause
WhereClause(;
over = nothing,
condition) =
new(over, condition)
end
WhereClause(condition; over = nothing) =
WhereClause(over = over, condition = condition)
"""
WHERE(; over = nothing, condition)
WHERE(condition; over = nothing)
A `WHERE` clause.
# Examples
```jldoctest
julia> c = FROM(:location) |>
WHERE(FUN("=", :zip, "60614")) |>
SELECT(:location_id);
julia> print(render(c))
SELECT "location_id"
FROM "location"
WHERE ("zip" = '60614')
```
"""
WHERE(args...; kws...) =
WhereClause(args...; kws...) |> SQLClause
dissect(scr::Symbol, ::typeof(WHERE), pats::Vector{Any}) =
dissect(scr, WhereClause, pats)
function PrettyPrinting.quoteof(c::WhereClause, ctx::QuoteContext)
ex = Expr(:call, nameof(WHERE), quoteof(c.condition, ctx))
if c.over !== nothing
ex = Expr(:call, :|>, quoteof(c.over, ctx), ex)
end
ex
end
rebase(c::WhereClause, c′) =
WhereClause(over = rebase(c.over, c′), condition = c.condition)