Fix the REPL-clearing-state bug.
This commit is contained in:
parent
9cb8cdc952
commit
73e9e1edc3
4 changed files with 35 additions and 7 deletions
26
README.md
26
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.
|
||||
|
||||
|
|
|
|||
|
|
@ -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 := ""
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue