Don’t reorder array items when fetching records

This commit is contained in:
Tobie Morgan Hitchcock 2019-02-05 18:47:05 +00:00
parent f8beab1e17
commit d3fea6365f
2 changed files with 19 additions and 9 deletions

View file

@ -92,15 +92,16 @@ func (e *executor) fetch(ctx context.Context, val interface{}, doc *data.Doc) (o
if len(path) > 0 {
switch res := val.(type) {
case []interface{}:
val := make([]interface{}, len(res))
for k, v := range res {
switch val := v.(type) {
switch tng := v.(type) {
case *sql.Thing:
res[k], _ = e.fetchThing(ctx, val, doc)
val[k], _ = e.fetchThing(ctx, tng, doc)
default:
res[k] = v
val[k] = v
}
}
return res
return val
case *sql.Thing:
val, _ = e.fetchThing(ctx, res, doc)
return val
@ -127,15 +128,16 @@ func (e *executor) fetch(ctx context.Context, val interface{}, doc *data.Doc) (o
if len(path) > 0 {
switch res := val.(type) {
case []interface{}:
val := make([]interface{}, len(res))
for k, v := range res {
switch val := v.(type) {
switch tng := v.(type) {
case *sql.Thing:
res[k], _ = e.fetchThing(ctx, val, doc)
val[k], _ = e.fetchThing(ctx, tng, doc)
default:
res[k] = v
val[k] = v
}
}
return res
return val
case *sql.Thing:
val, _ = e.fetchThing(ctx, res, doc)
return val

View file

@ -250,7 +250,15 @@ func (d *document) yield(ctx context.Context, stm sql.Statement, output sql.Toke
switch res := val.(type) {
case []interface{}:
val, _ = d.i.e.fetchArray(ctx, res, doc)
val := make([]interface{}, len(res))
for k, v := range res {
switch tng := v.(type) {
case *sql.Thing:
val[k], _ = d.i.e.fetchThing(ctx, tng, doc)
default:
val[k] = v
}
}
out.Set(val, key)
case *sql.Thing:
val, _ = d.i.e.fetchThing(ctx, res, doc)