Destutter gremlin.GremlinResult

This commit is contained in:
kortschak 2014-08-02 22:49:57 +09:30
parent 15a45ef0d4
commit bf3ac2be9e
4 changed files with 12 additions and 11 deletions

View file

@ -84,7 +84,7 @@ func setupGremlin(env *otto.Otto, ses *Session) {
graph.Set("Emit", func(call otto.FunctionCall) otto.Value {
value := call.Argument(0)
if value.IsDefined() {
ses.SendResult(&GremlinResult{val: &value})
ses.SendResult(&Result{val: &value})
}
return otto.NullValue()
})

View file

@ -267,7 +267,7 @@ func runIteratorOnSession(it graph.Iterator, ses *Session) {
}
tags := make(map[string]graph.Value)
it.TagResults(tags)
if !ses.SendResult(&GremlinResult{actualResults: &tags}) {
if !ses.SendResult(&Result{actualResults: &tags}) {
break
}
for it.NextResult() == true {
@ -278,7 +278,7 @@ func runIteratorOnSession(it graph.Iterator, ses *Session) {
}
tags := make(map[string]graph.Value)
it.TagResults(tags)
if !ses.SendResult(&GremlinResult{actualResults: &tags}) {
if !ses.SendResult(&Result{actualResults: &tags}) {
break
}
}

View file

@ -20,8 +20,9 @@ import (
"testing"
"github.com/google/cayley/graph"
_ "github.com/google/cayley/graph/memstore"
"github.com/google/cayley/quad"
_ "github.com/google/cayley/graph/memstore"
)
// This is a simple test graph.
@ -252,7 +253,7 @@ func runQueryGetTag(g []*quad.Quad, query string, tag string) []string {
var results []string
for res := range c {
data := res.(*GremlinResult)
data := res.(*Result)
if data.val == nil {
val := (*data.actualResults)[tag]
if val != nil {

View file

@ -60,7 +60,7 @@ func NewSession(inputTripleStore graph.TripleStore, timeoutSec int, persist bool
return &g
}
type GremlinResult struct {
type Result struct {
metaresult bool
err error
val *otto.Value
@ -89,7 +89,7 @@ func (s *Session) InputParses(input string) (query.ParseResult, error) {
return query.Parsed, nil
}
func (s *Session) SendResult(result *GremlinResult) bool {
func (s *Session) SendResult(r *Result) bool {
if s.limit >= 0 && s.limit == s.count {
return false
}
@ -99,7 +99,7 @@ func (s *Session) SendResult(result *GremlinResult) bool {
default:
}
if s.results != nil {
s.results <- result
s.results <- r
s.count++
if s.limit >= 0 && s.limit == s.count {
return false
@ -156,7 +156,7 @@ func (s *Session) ExecInput(input string, out chan interface{}, limit int) {
} else {
value, err = s.runUnsafe(s.script)
}
out <- &GremlinResult{
out <- &Result{
metaresult: true,
err: err,
val: &value,
@ -169,7 +169,7 @@ func (s *Session) ExecInput(input string, out chan interface{}, limit int) {
}
func (s *Session) ToText(result interface{}) string {
data := result.(*GremlinResult)
data := result.(*Result)
if data.metaresult {
if data.err != nil {
return fmt.Sprintf("Error: %v\n", data.err)
@ -220,7 +220,7 @@ func (s *Session) ToText(result interface{}) string {
// Web stuff
func (s *Session) BuildJson(result interface{}) {
data := result.(*GremlinResult)
data := result.(*Result)
if !data.metaresult {
if data.val == nil {
obj := make(map[string]string)