Destutter gremlin.GremlinResult
This commit is contained in:
parent
15a45ef0d4
commit
bf3ac2be9e
4 changed files with 12 additions and 11 deletions
|
|
@ -84,7 +84,7 @@ func setupGremlin(env *otto.Otto, ses *Session) {
|
||||||
graph.Set("Emit", func(call otto.FunctionCall) otto.Value {
|
graph.Set("Emit", func(call otto.FunctionCall) otto.Value {
|
||||||
value := call.Argument(0)
|
value := call.Argument(0)
|
||||||
if value.IsDefined() {
|
if value.IsDefined() {
|
||||||
ses.SendResult(&GremlinResult{val: &value})
|
ses.SendResult(&Result{val: &value})
|
||||||
}
|
}
|
||||||
return otto.NullValue()
|
return otto.NullValue()
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -267,7 +267,7 @@ func runIteratorOnSession(it graph.Iterator, ses *Session) {
|
||||||
}
|
}
|
||||||
tags := make(map[string]graph.Value)
|
tags := make(map[string]graph.Value)
|
||||||
it.TagResults(tags)
|
it.TagResults(tags)
|
||||||
if !ses.SendResult(&GremlinResult{actualResults: &tags}) {
|
if !ses.SendResult(&Result{actualResults: &tags}) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
for it.NextResult() == true {
|
for it.NextResult() == true {
|
||||||
|
|
@ -278,7 +278,7 @@ func runIteratorOnSession(it graph.Iterator, ses *Session) {
|
||||||
}
|
}
|
||||||
tags := make(map[string]graph.Value)
|
tags := make(map[string]graph.Value)
|
||||||
it.TagResults(tags)
|
it.TagResults(tags)
|
||||||
if !ses.SendResult(&GremlinResult{actualResults: &tags}) {
|
if !ses.SendResult(&Result{actualResults: &tags}) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,9 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/google/cayley/graph"
|
"github.com/google/cayley/graph"
|
||||||
_ "github.com/google/cayley/graph/memstore"
|
|
||||||
"github.com/google/cayley/quad"
|
"github.com/google/cayley/quad"
|
||||||
|
|
||||||
|
_ "github.com/google/cayley/graph/memstore"
|
||||||
)
|
)
|
||||||
|
|
||||||
// This is a simple test graph.
|
// This is a simple test graph.
|
||||||
|
|
@ -252,7 +253,7 @@ func runQueryGetTag(g []*quad.Quad, query string, tag string) []string {
|
||||||
|
|
||||||
var results []string
|
var results []string
|
||||||
for res := range c {
|
for res := range c {
|
||||||
data := res.(*GremlinResult)
|
data := res.(*Result)
|
||||||
if data.val == nil {
|
if data.val == nil {
|
||||||
val := (*data.actualResults)[tag]
|
val := (*data.actualResults)[tag]
|
||||||
if val != nil {
|
if val != nil {
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ func NewSession(inputTripleStore graph.TripleStore, timeoutSec int, persist bool
|
||||||
return &g
|
return &g
|
||||||
}
|
}
|
||||||
|
|
||||||
type GremlinResult struct {
|
type Result struct {
|
||||||
metaresult bool
|
metaresult bool
|
||||||
err error
|
err error
|
||||||
val *otto.Value
|
val *otto.Value
|
||||||
|
|
@ -89,7 +89,7 @@ func (s *Session) InputParses(input string) (query.ParseResult, error) {
|
||||||
return query.Parsed, nil
|
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 {
|
if s.limit >= 0 && s.limit == s.count {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
@ -99,7 +99,7 @@ func (s *Session) SendResult(result *GremlinResult) bool {
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
if s.results != nil {
|
if s.results != nil {
|
||||||
s.results <- result
|
s.results <- r
|
||||||
s.count++
|
s.count++
|
||||||
if s.limit >= 0 && s.limit == s.count {
|
if s.limit >= 0 && s.limit == s.count {
|
||||||
return false
|
return false
|
||||||
|
|
@ -156,7 +156,7 @@ func (s *Session) ExecInput(input string, out chan interface{}, limit int) {
|
||||||
} else {
|
} else {
|
||||||
value, err = s.runUnsafe(s.script)
|
value, err = s.runUnsafe(s.script)
|
||||||
}
|
}
|
||||||
out <- &GremlinResult{
|
out <- &Result{
|
||||||
metaresult: true,
|
metaresult: true,
|
||||||
err: err,
|
err: err,
|
||||||
val: &value,
|
val: &value,
|
||||||
|
|
@ -169,7 +169,7 @@ func (s *Session) ExecInput(input string, out chan interface{}, limit int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Session) ToText(result interface{}) string {
|
func (s *Session) ToText(result interface{}) string {
|
||||||
data := result.(*GremlinResult)
|
data := result.(*Result)
|
||||||
if data.metaresult {
|
if data.metaresult {
|
||||||
if data.err != nil {
|
if data.err != nil {
|
||||||
return fmt.Sprintf("Error: %v\n", data.err)
|
return fmt.Sprintf("Error: %v\n", data.err)
|
||||||
|
|
@ -220,7 +220,7 @@ func (s *Session) ToText(result interface{}) string {
|
||||||
|
|
||||||
// Web stuff
|
// Web stuff
|
||||||
func (s *Session) BuildJson(result interface{}) {
|
func (s *Session) BuildJson(result interface{}) {
|
||||||
data := result.(*GremlinResult)
|
data := result.(*Result)
|
||||||
if !data.metaresult {
|
if !data.metaresult {
|
||||||
if data.val == nil {
|
if data.val == nil {
|
||||||
obj := make(map[string]string)
|
obj := make(map[string]string)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue