diff --git a/README.md b/README.md index a1e947e..78f9578 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,31 @@ make And the `cayley` binary will be built and ready. Give it a quick test with: -``` ./cayley repl --dbpath=testdata.nt ``` +``` +./cayley repl --dbpath=testdata.nt +``` + +You should see a `cayley>` REPL prompt. Go ahead and give it a try: + +``` +// Simple math +cayley> 2 + 2 + +// Javascript syntax +cayley> x = 2 * 8 +cayley> x + +// See all the entities in this small follow graph. +cayley> graph.Vertex().All() + +// See only dani. +cayley> graph.Vertex("dani").All() + +// See who dani follows. +cayley> graph.Vertex("dani").Out("follows").All() +``` + +**Sample Data** For somewhat more interesting data, a sample of 30k movies from Freebase comes in the checkout. diff --git a/src/cayley_cmd/cayley-repl.go b/src/cayley_cmd/cayley-repl.go index d410da4..9c4757a 100644 --- a/src/cayley_cmd/cayley-repl.go +++ b/src/cayley_cmd/cayley-repl.go @@ -69,7 +69,7 @@ func CayleyRepl(ts graph.TripleStore, queryLanguage string, config *cfg.CayleyCo case "gremlin": fallthrough default: - ses = gremlin.NewGremlinSession(ts, config.GremlinTimeout) + ses = gremlin.NewGremlinSession(ts, config.GremlinTimeout, true) } inputBf := bufio.NewReader(os.Stdin) line := "" diff --git a/src/cayley_http/cayley-http-query.go b/src/cayley_http/cayley-http-query.go index 63a2080..c3a91e6 100644 --- a/src/cayley_http/cayley-http-query.go +++ b/src/cayley_http/cayley-http-query.go @@ -69,7 +69,7 @@ func (api *Api) ServeV1Query(w http.ResponseWriter, r *http.Request, params http var ses graph.HttpSession switch params.ByName("query_lang") { case "gremlin": - ses = gremlin.NewGremlinSession(api.ts, api.config.GremlinTimeout) + ses = gremlin.NewGremlinSession(api.ts, api.config.GremlinTimeout, false) case "mql": ses = mql.NewMqlSession(api.ts) default: @@ -118,7 +118,7 @@ func (api *Api) ServeV1Shape(w http.ResponseWriter, r *http.Request, params http var ses graph.HttpSession switch params.ByName("query_lang") { case "gremlin": - ses = gremlin.NewGremlinSession(api.ts, api.config.GremlinTimeout) + ses = gremlin.NewGremlinSession(api.ts, api.config.GremlinTimeout, false) case "mql": ses = mql.NewMqlSession(api.ts) default: diff --git a/src/gremlin/gremlin-session.go b/src/gremlin/gremlin-session.go index 6e5990e..25b3fbb 100644 --- a/src/gremlin/gremlin-session.go +++ b/src/gremlin/gremlin-session.go @@ -37,15 +37,19 @@ type GremlinSession struct { script *otto.Script doHalt bool timeoutSec time.Duration + emptyEnv *otto.Otto } -func NewGremlinSession(inputTripleStore graph.TripleStore, timeoutSec int) *GremlinSession { +func NewGremlinSession(inputTripleStore graph.TripleStore, timeoutSec int, persist bool) *GremlinSession { var g GremlinSession g.ts = inputTripleStore g.env = BuildGremlinEnv(&g) g.limit = -1 g.count = 0 g.lookingForQueryShape = false + if persist { + g.emptyEnv = g.env + } if timeoutSec < 0 { g.timeoutSec = time.Duration(-1) } else { @@ -127,7 +131,7 @@ func (g *GremlinSession) runUnsafe(input interface{}) (otto.Value, error) { g.env.Interrupt <- func() { panic(halt) } - g.env = nil + g.env = g.emptyEnv } }() } @@ -159,7 +163,7 @@ func (g *GremlinSession) ExecInput(input string, out chan interface{}, limit int } g.currentChannel = nil g.script = nil - g.env = nil + g.env = g.emptyEnv return }