dictyBase/arangomanager

View on GitHub
result.go

Summary

Maintainability
A
0 mins
Test Coverage
package arangomanager

import (
    "context"
    "fmt"

    driver "github.com/arangodb/go-driver"
    "github.com/fatih/structs"
)

// Result is a cursor for single row of data.
type Result struct {
    cursor driver.Cursor
    empty  bool
}

// IsEmpty checks for empty result.
func (r *Result) IsEmpty() bool {
    return r.empty
}

// Read read the row of data to i interface.
func (r *Result) Read(iface interface{}) error {
    meta, err := r.cursor.ReadDocument(context.TODO(), iface)
    if err != nil {
        return fmt.Errorf("error in reading document %s", err)
    }
    if !structs.IsStruct(iface) {
        return nil
    }
    s := structs.New(iface)
    if f, ok := s.FieldOk("DocumentMeta"); ok {
        if f.IsEmbedded() {
            if err := f.Set(meta); err != nil {
                return fmt.Errorf("error in assigning DocumentMeta to the structure %s", err)
            }
        }
    }

    return nil
}