Prevent circular references when yielding data

This commit is contained in:
Tobie Morgan Hitchcock 2017-12-04 22:20:39 +00:00
parent 8fadbc9f35
commit 5c7378c9c7
8 changed files with 14 additions and 8 deletions

View file

@ -258,7 +258,13 @@ func (d *document) yield(ctx context.Context, stm sql.Statement, output sql.Toke
if err != nil { if err != nil {
return nil, err return nil, err
} }
doc.Set(v, e.Field)
switch v {
case d.current:
doc.Set(nil, e.Field)
default:
doc.Set(v, e.Field)
}
} }

View file

@ -80,7 +80,7 @@ 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, varKeyParent) vars.Set(doc.Data(), varKeyParent)
ctx = context.WithValue(ctx, ctxKeySubs, vars) ctx = context.WithValue(ctx, ctxKeySubs, vars)
} }

View file

@ -79,7 +79,7 @@ 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, varKeyParent) vars.Set(doc.Data(), varKeyParent)
ctx = context.WithValue(ctx, ctxKeySubs, vars) ctx = context.WithValue(ctx, ctxKeySubs, vars)
} }

View file

@ -58,7 +58,7 @@ 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, varKeyParent) vars.Set(doc.Data(), varKeyParent)
ctx = context.WithValue(ctx, ctxKeySubs, vars) ctx = context.WithValue(ctx, ctxKeySubs, vars)
} }

View file

@ -72,7 +72,7 @@ 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, varKeyParent) vars.Set(doc.Data(), varKeyParent)
ctx = context.WithValue(ctx, ctxKeySubs, vars) ctx = context.WithValue(ctx, ctxKeySubs, vars)
} }

View file

@ -86,7 +86,7 @@ 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, varKeyParent) vars.Set(doc.Data(), varKeyParent)
ctx = context.WithValue(ctx, ctxKeySubs, vars) ctx = context.WithValue(ctx, ctxKeySubs, vars)
} }

View file

@ -79,7 +79,7 @@ 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, varKeyParent) vars.Set(doc.Data(), varKeyParent)
ctx = context.WithValue(ctx, ctxKeySubs, vars) ctx = context.WithValue(ctx, ctxKeySubs, vars)
} }

View file

@ -58,7 +58,7 @@ 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, varKeyParent) vars.Set(doc.Data(), varKeyParent)
ctx = context.WithValue(ctx, ctxKeySubs, vars) ctx = context.WithValue(ctx, ctxKeySubs, vars)
} }