diff --git a/db/check.go b/db/check.go index 8e17600a..146b13ac 100644 --- a/db/check.go +++ b/db/check.go @@ -194,7 +194,7 @@ func (d *document) event(ctx context.Context, when method) (err error) { vars.Set(d.id, varKeyThis) vars.Set(d.current.Data(), varKeyAfter) vars.Set(d.initial.Data(), varKeyBefore) - ctx = context.WithValue(ctx, ctxKeySubs, vars) + ctx = context.WithValue(ctx, ctxKeySpec, vars) for _, ev := range evs { diff --git a/db/fetch.go b/db/fetch.go index bef98918..e2b707ae 100644 --- a/db/fetch.go +++ b/db/fetch.go @@ -90,38 +90,24 @@ func (e *executor) fetch(ctx context.Context, val interface{}, doc *data.Doc) (o case *sql.Param: - if obj, ok := ctx.Value(ctxKeySubs).(*data.Doc); ok { + for _, s := range paramSearchKeys { - obj.Fetch(func(key string, val interface{}) interface{} { - switch res := val.(type) { - case *sql.Thing: - val, _ = e.fetchThing(ctx, res, doc) - return val - default: - return val + if obj, ok := ctx.Value(s).(*data.Doc); ok { + + obj.Fetch(func(key string, val interface{}) interface{} { + switch res := val.(type) { + case *sql.Thing: + val, _ = e.fetchThing(ctx, res, doc) + return val + default: + return val + } + }) + + if res := obj.Get(val.ID).Data(); res != nil { + return e.fetch(ctx, res, doc) } - }) - if res := obj.Get(val.ID).Data(); res != nil { - return e.fetch(ctx, res, doc) - } - - } - - if obj, ok := ctx.Value(ctxKeyVars).(*data.Doc); ok { - - obj.Fetch(func(key string, val interface{}) interface{} { - switch res := val.(type) { - case *sql.Thing: - val, _ = e.fetchThing(ctx, res, doc) - return val - default: - return val - } - }) - - if res := obj.Get(val.ID).Data(); res != nil { - return e.fetch(ctx, res, doc) } } diff --git a/db/merge.go b/db/merge.go index 64467b3a..5404e6c5 100644 --- a/db/merge.go +++ b/db/merge.go @@ -291,7 +291,7 @@ func (d *document) mrgFld(ctx context.Context) (err error) { vars.Set(val, varKeyValue) vars.Set(val, varKeyAfter) vars.Set(old, varKeyBefore) - ctx = context.WithValue(ctx, ctxKeySubs, vars) + ctx = context.WithValue(ctx, ctxKeySpec, vars) // We are setting the value of the field @@ -306,7 +306,7 @@ func (d *document) mrgFld(ctx context.Context) (err error) { vars.Set(val, varKeyValue) vars.Set(val, varKeyAfter) vars.Set(old, varKeyBefore) - ctx = context.WithValue(ctx, ctxKeySubs, vars) + ctx = context.WithValue(ctx, ctxKeySpec, vars) // We are checking the value of the field diff --git a/db/vars.go b/db/vars.go index 88a5643b..b50932af 100644 --- a/db/vars.go +++ b/db/vars.go @@ -40,6 +40,7 @@ const ( ctxKeyDb = "db" ctxKeyVars = "vars" ctxKeySubs = "subs" + ctxKeySpec = "spec" ctxKeyAuth = "auth" ctxKeyKind = "kind" ctxKeyScope = "scope" @@ -63,4 +64,5 @@ var ( queryNotExecuted = errors.New("Query not executed") queryIdentFailed = errors.New("Found ident but no doc available") featureNotImplemented = errors.New("Feature is not yet implemented") + paramSearchKeys = []string{ctxKeySpec, ctxKeySubs, ctxKeyVars} )