Ensure sub-queries can access super-parent queries correctly
This commit is contained in:
parent
fd0abd2d8e
commit
8bf36e8bf2
7 changed files with 21 additions and 14 deletions
|
@ -96,11 +96,12 @@ func (e *executor) fetchCreate(ctx context.Context, stm *sql.CreateStatement, do
|
||||||
if doc != nil {
|
if doc != nil {
|
||||||
vars := data.New()
|
vars := data.New()
|
||||||
vars.Set(doc.Data(), varKeyParent)
|
vars.Set(doc.Data(), varKeyParent)
|
||||||
vars.Array(varKeyParents)
|
|
||||||
if subs := ctx.Value(ctxKeySubs); subs != nil {
|
if subs := ctx.Value(ctxKeySubs); subs != nil {
|
||||||
if subs, ok := subs.(*data.Doc); ok {
|
if subs, ok := subs.(*data.Doc); ok {
|
||||||
vars.Append(subs.Get(varKeyParents).Data(), varKeyParents)
|
vars.Set(subs.Get(varKeyParents).Data(), varKeyParents)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
vars.Array(varKeyParents)
|
||||||
}
|
}
|
||||||
vars.Append(doc.Data(), varKeyParents)
|
vars.Append(doc.Data(), varKeyParents)
|
||||||
ctx = context.WithValue(ctx, ctxKeySubs, vars)
|
ctx = context.WithValue(ctx, ctxKeySubs, vars)
|
||||||
|
|
|
@ -95,11 +95,12 @@ func (e *executor) fetchDelete(ctx context.Context, stm *sql.DeleteStatement, do
|
||||||
if doc != nil {
|
if doc != nil {
|
||||||
vars := data.New()
|
vars := data.New()
|
||||||
vars.Set(doc.Data(), varKeyParent)
|
vars.Set(doc.Data(), varKeyParent)
|
||||||
vars.Array(varKeyParents)
|
|
||||||
if subs := ctx.Value(ctxKeySubs); subs != nil {
|
if subs := ctx.Value(ctxKeySubs); subs != nil {
|
||||||
if subs, ok := subs.(*data.Doc); ok {
|
if subs, ok := subs.(*data.Doc); ok {
|
||||||
vars.Append(subs.Get(varKeyParents).Data(), varKeyParents)
|
vars.Set(subs.Get(varKeyParents).Data(), varKeyParents)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
vars.Array(varKeyParents)
|
||||||
}
|
}
|
||||||
vars.Append(doc.Data(), varKeyParents)
|
vars.Append(doc.Data(), varKeyParents)
|
||||||
ctx = context.WithValue(ctx, ctxKeySubs, vars)
|
ctx = context.WithValue(ctx, ctxKeySubs, vars)
|
||||||
|
|
|
@ -64,11 +64,12 @@ func (e *executor) fetchInsert(ctx context.Context, stm *sql.InsertStatement, do
|
||||||
if doc != nil {
|
if doc != nil {
|
||||||
vars := data.New()
|
vars := data.New()
|
||||||
vars.Set(doc.Data(), varKeyParent)
|
vars.Set(doc.Data(), varKeyParent)
|
||||||
vars.Array(varKeyParents)
|
|
||||||
if subs := ctx.Value(ctxKeySubs); subs != nil {
|
if subs := ctx.Value(ctxKeySubs); subs != nil {
|
||||||
if subs, ok := subs.(*data.Doc); ok {
|
if subs, ok := subs.(*data.Doc); ok {
|
||||||
vars.Append(subs.Get(varKeyParents).Data(), varKeyParents)
|
vars.Set(subs.Get(varKeyParents).Data(), varKeyParents)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
vars.Array(varKeyParents)
|
||||||
}
|
}
|
||||||
vars.Append(doc.Data(), varKeyParents)
|
vars.Append(doc.Data(), varKeyParents)
|
||||||
ctx = context.WithValue(ctx, ctxKeySubs, vars)
|
ctx = context.WithValue(ctx, ctxKeySubs, vars)
|
||||||
|
|
|
@ -88,11 +88,12 @@ func (e *executor) fetchRelate(ctx context.Context, stm *sql.RelateStatement, do
|
||||||
if doc != nil {
|
if doc != nil {
|
||||||
vars := data.New()
|
vars := data.New()
|
||||||
vars.Set(doc.Data(), varKeyParent)
|
vars.Set(doc.Data(), varKeyParent)
|
||||||
vars.Array(varKeyParents)
|
|
||||||
if subs := ctx.Value(ctxKeySubs); subs != nil {
|
if subs := ctx.Value(ctxKeySubs); subs != nil {
|
||||||
if subs, ok := subs.(*data.Doc); ok {
|
if subs, ok := subs.(*data.Doc); ok {
|
||||||
vars.Append(subs.Get(varKeyParents).Data(), varKeyParents)
|
vars.Set(subs.Get(varKeyParents).Data(), varKeyParents)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
vars.Array(varKeyParents)
|
||||||
}
|
}
|
||||||
vars.Append(doc.Data(), varKeyParents)
|
vars.Append(doc.Data(), varKeyParents)
|
||||||
ctx = context.WithValue(ctx, ctxKeySubs, vars)
|
ctx = context.WithValue(ctx, ctxKeySubs, vars)
|
||||||
|
|
|
@ -96,11 +96,12 @@ func (e *executor) fetchSelect(ctx context.Context, stm *sql.SelectStatement, do
|
||||||
if doc != nil {
|
if doc != nil {
|
||||||
vars := data.New()
|
vars := data.New()
|
||||||
vars.Set(doc.Data(), varKeyParent)
|
vars.Set(doc.Data(), varKeyParent)
|
||||||
vars.Array(varKeyParents)
|
|
||||||
if subs := ctx.Value(ctxKeySubs); subs != nil {
|
if subs := ctx.Value(ctxKeySubs); subs != nil {
|
||||||
if subs, ok := subs.(*data.Doc); ok {
|
if subs, ok := subs.(*data.Doc); ok {
|
||||||
vars.Append(subs.Get(varKeyParents).Data(), varKeyParents)
|
vars.Set(subs.Get(varKeyParents).Data(), varKeyParents)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
vars.Array(varKeyParents)
|
||||||
}
|
}
|
||||||
vars.Append(doc.Data(), varKeyParents)
|
vars.Append(doc.Data(), varKeyParents)
|
||||||
ctx = context.WithValue(ctx, ctxKeySubs, vars)
|
ctx = context.WithValue(ctx, ctxKeySubs, vars)
|
||||||
|
|
|
@ -95,11 +95,12 @@ func (e *executor) fetchUpdate(ctx context.Context, stm *sql.UpdateStatement, do
|
||||||
if doc != nil {
|
if doc != nil {
|
||||||
vars := data.New()
|
vars := data.New()
|
||||||
vars.Set(doc.Data(), varKeyParent)
|
vars.Set(doc.Data(), varKeyParent)
|
||||||
vars.Array(varKeyParents)
|
|
||||||
if subs := ctx.Value(ctxKeySubs); subs != nil {
|
if subs := ctx.Value(ctxKeySubs); subs != nil {
|
||||||
if subs, ok := subs.(*data.Doc); ok {
|
if subs, ok := subs.(*data.Doc); ok {
|
||||||
vars.Append(subs.Get(varKeyParents).Data(), varKeyParents)
|
vars.Set(subs.Get(varKeyParents).Data(), varKeyParents)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
vars.Array(varKeyParents)
|
||||||
}
|
}
|
||||||
vars.Append(doc.Data(), varKeyParents)
|
vars.Append(doc.Data(), varKeyParents)
|
||||||
ctx = context.WithValue(ctx, ctxKeySubs, vars)
|
ctx = context.WithValue(ctx, ctxKeySubs, vars)
|
||||||
|
|
|
@ -64,11 +64,12 @@ func (e *executor) fetchUpsert(ctx context.Context, stm *sql.UpsertStatement, do
|
||||||
if doc != nil {
|
if doc != nil {
|
||||||
vars := data.New()
|
vars := data.New()
|
||||||
vars.Set(doc.Data(), varKeyParent)
|
vars.Set(doc.Data(), varKeyParent)
|
||||||
vars.Array(varKeyParents)
|
|
||||||
if subs := ctx.Value(ctxKeySubs); subs != nil {
|
if subs := ctx.Value(ctxKeySubs); subs != nil {
|
||||||
if subs, ok := subs.(*data.Doc); ok {
|
if subs, ok := subs.(*data.Doc); ok {
|
||||||
vars.Append(subs.Get(varKeyParents).Data(), varKeyParents)
|
vars.Set(subs.Get(varKeyParents).Data(), varKeyParents)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
vars.Array(varKeyParents)
|
||||||
}
|
}
|
||||||
vars.Append(doc.Data(), varKeyParents)
|
vars.Append(doc.Data(), varKeyParents)
|
||||||
ctx = context.WithValue(ctx, ctxKeySubs, vars)
|
ctx = context.WithValue(ctx, ctxKeySubs, vars)
|
||||||
|
|
Loading…
Reference in a new issue