Skip to content

Commit a35594c

Browse files
committed
Make nested records visible
1 parent 24d180f commit a35594c

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/link.jl

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,26 @@ struct LinkContext
2525
knot_refs)
2626
end
2727

28-
function link(q::SQLQuery)
29-
@dissect(q, (local tail) |> WithContext(catalog = (local catalog))) || throw(IllFormedError())
30-
ctx = LinkContext(catalog)
31-
t = row_type(tail)
28+
function _select(t::RowType)
3229
refs = SQLQuery[]
3330
for (f, ft) in t.fields
3431
if ft isa ScalarType
3532
push!(refs, Get(f))
33+
else
34+
nested_refs = _select(ft)
35+
for nested_ref in nested_refs
36+
push!(refs, Nested(over = nested_ref, name = f))
37+
end
3638
end
3739
end
40+
refs
41+
end
42+
43+
function link(q::SQLQuery)
44+
@dissect(q, (local tail) |> WithContext(catalog = (local catalog))) || throw(IllFormedError())
45+
ctx = LinkContext(catalog)
46+
t = row_type(tail)
47+
refs = _select(t)
3848
tail′ = Linked(refs, tail = link(dismantle(tail, ctx), ctx, refs))
3949
WithContext(tail = tail′, catalog = catalog, defs = ctx.defs)
4050
end
@@ -555,12 +565,9 @@ end
555565
function gather!(n::IsolatedNode, ctx)
556566
def = ctx.defs[n.idx]
557567
!@dissect(def, Linked()) || return
558-
refs = SQLQuery[]
559-
for (f, ft) in n.type.fields
560-
if ft isa ScalarType
561-
push!(refs, Get(f))
562-
break
563-
end
568+
refs = _select(n.type)
569+
if !isempty(refs)
570+
refs = refs[1:1]
564571
end
565572
def′ = Linked(refs, tail = link(def, ctx, refs))
566573
ctx.defs[n.idx] = def′

0 commit comments

Comments
 (0)