/
from.jl
45 lines (33 loc) · 887 Bytes
/
from.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
# FROM clause.
mutable struct FromClause <: AbstractSQLClause
over::Union{SQLClause, Nothing}
FromClause(; over = nothing) =
new(over)
end
FromClause(over) =
FromClause(over = over)
"""
FROM(; over = nothing)
FROM(over)
A `FROM` clause.
# Examples
```jldoctest
julia> c = ID(:person) |> AS(:p) |> FROM() |> SELECT((:p, :person_id));
julia> print(render(c))
SELECT "p"."person_id"
FROM "person" AS "p"
```
"""
FROM(args...; kws...) =
FromClause(args...; kws...) |> SQLClause
dissect(scr::Symbol, ::typeof(FROM), pats::Vector{Any}) =
dissect(scr, FromClause, pats)
function PrettyPrinting.quoteof(c::FromClause, ctx::QuoteContext)
ex = Expr(:call, nameof(FROM))
if c.over !== nothing
ex = Expr(:call, :|>, quoteof(c.over, ctx), ex)
end
ex
end
rebase(c::FromClause, c′) =
FromClause(over = rebase(c.over, c′))