Skip to content

Commit

Permalink
Fixed presentation scope and conditional boxes
Browse files Browse the repository at this point in the history
  • Loading branch information
bosonbaas committed Oct 22, 2021
1 parent ae61e20 commit a6c86a2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 43 deletions.
75 changes: 33 additions & 42 deletions src/Presentations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,54 +42,45 @@ module Presentations
end

macro present_to_schema(head)
present_to_schema(head.args[1], eval(GlobalRef(Main, head.args[2])))
present_to_schema(head.args[1], head.args[2])
end

function present_to_schema(sch_name::Symbol, wf::Presentation)
gens = Array{GATExpr, 1}()
tables = Dict{Symbol, GATExpr}()
sym_app(s::Symbol, suffix::String) = Symbol(string(s, suffix))
get_syms(g::Union{GATExpr, Array}) = begin
if g isa Array
if eltype(g) == Symbol
return [g]
function present_to_schema(sch_name::Symbol, wf::Symbol)
quote
gens = Array{GATExpr, 1}()
tables = Dict{Symbol, GATExpr}()
sym_app(s::Symbol, suffix::String) = Symbol(string(s, suffix))
get_syms(g::Union{GATExpr, Array}) = begin
if g isa Array
if eltype(g) == Symbol
return [g]
end
sym_array = Array{Array{Symbol, 1}, 1}()
for i in g
append!(sym_array, get_syms(i))
end
return sym_array
elseif hasprop(g, :args)
return get_syms(g.args)
end
sym_array = Array{Array{Symbol, 1}, 1}()
for i in g
append!(sym_array, get_syms(i))
end
return sym_array
elseif hasprop(g, :args)
return get_syms(g.args)
end
end

# Evaluate objects to tables with attributes
#for g in generators(wf, :Ob)
# g_name = g.args[1]
# tab_name = sym_app(g_name, "_T")
# table = Ob(FreeSchema, tab_name)
# tables[g_name] = table
# push!(gens, table)
# push!(gens, Attr(sym_app(tab_name, "_1_id"), table, generator(TheorySQL, :Int64)))
# push!(gens, Attr(sym_app(tab_name, "_1_data"), table, generator(TheorySQL, g.args[2])))
#end

# Evaluate homs to purely data-connected tables
for g in generators(wf, :Hom)
g_name = g.args[1]
table = Ob(FreeSchema, g_name)
tables[g_name] = table
push!(gens, table)
append!(gens, map(enumerate(get_syms(g.type_args))) do (i, sym)
Attr(sym_app(g_name, "_$(i)_$(sym[1])$i"),
table, generator(TheorySQL, sym[2]))
end)
end
# Evaluate homs to purely data-connected tables
for g in generators($(esc(wf)), :Hom)
g_name = g.args[1]
table = Ob(FreeSchema, g_name)
tables[g_name] = table
push!(gens, table)
append!(gens, map(enumerate(get_syms(g.type_args))) do (i, sym)
Attr(sym_app(g_name, "_$(i)_$(sym[1])$i"),
table, generator(TheorySQL, sym[2]))
end)
end

@present p <: TheorySQL begin end
add_generators!(p, gens)
:($(esc(:(@db_schema $(sch_name)($p)))))
@present p <: TheorySQL begin end
add_generators!(p, gens)
$(esc(:eval))(:(@db_schema $($(Meta.quot(sch_name)))($(p))))
end
end

function draw_schema(p::Presentation; kw...)
Expand Down
2 changes: 1 addition & 1 deletion src/Queries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ module Queries
# add comparison references for later type-inference
if name in keys(SQLOperators)
add_part!(q, :Comparison, comp_port1=ports[1], comp_port2=ports[2])
set_subparts!(q, 1:2, port_name=SQLOperators[name][2][1:2], port_type=[nothing, nothing])
set_subparts!(q, ports, port_name=SQLOperators[name][2][1:2], port_type=[nothing, nothing])
else
fields = [port_names[name][i][1] for i in 1:length(ports)]
types = [Symbol(port_names[name][i][2]) for i in 1:length(ports)]
Expand Down

0 comments on commit a6c86a2

Please sign in to comment.