本文整理汇总了Golang中github.com/google/cayley/query.Session类的典型用法代码示例。如果您正苦于以下问题:Golang Session类的具体用法?Golang Session怎么用?Golang Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Session类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Run
func Run(query string, ses query.Session) {
nResults := 0
startTrace, startTime := trace("Elapsed time: %g ms\n\n")
defer func() {
if nResults > 0 {
un(startTrace, startTime)
}
}()
fmt.Printf("\n")
c := make(chan interface{}, 5)
go ses.ExecInput(query, c, 100)
for res := range c {
fmt.Print(ses.ToText(res))
nResults++
}
if nResults > 0 {
fmt.Printf("-----------\n%d Results\n", nResults)
}
}
开发者ID:jacqui,项目名称:cayley,代码行数:19,代码来源:repl.go
示例2: Run
func Run(query string, ses query.Session) {
nResults := 0
startTrace, startTime := trace("Elapsed time: %g ms\n\n")
defer func() {
if nResults > 0 {
un(startTrace, startTime)
}
}()
fmt.Printf("\n")
c := make(chan interface{}, 5)
go ses.Execute(query, c, 100)
for res := range c {
fmt.Print(ses.Format(res))
nResults++
}
if nResults > 0 {
results := "Result"
if nResults > 1 {
results += "s"
}
fmt.Printf("-----------\n%d %s\n", nResults, results)
}
}
开发者ID:dennwc,项目名称:cayley,代码行数:23,代码来源:repl.go
示例3: Repl
func Repl(ts graph.TripleStore, queryLanguage string, cfg *config.Config) error {
var ses query.Session
switch queryLanguage {
case "sexp":
ses = sexp.NewSession(ts)
case "mql":
ses = mql.NewSession(ts)
case "gremlin":
fallthrough
default:
ses = gremlin.NewSession(ts, cfg.Timeout, true)
}
buf := bufio.NewReader(os.Stdin)
var line []byte
for {
if len(line) == 0 {
fmt.Print("cayley> ")
} else {
fmt.Print("... ")
}
l, prefix, err := buf.ReadLine()
if err == io.EOF {
if len(line) != 0 {
line = line[:0]
} else {
return nil
}
}
if err != nil {
line = line[:0]
}
if prefix {
return errors.New("line too long")
}
line = append(line, l...)
if len(line) == 0 {
continue
}
line = bytes.TrimSpace(line)
if len(line) == 0 || line[0] == '#' {
line = line[:0]
continue
}
if bytes.HasPrefix(line, []byte(":debug")) {
ses.ToggleDebug()
fmt.Println("Debug Toggled")
line = line[:0]
continue
}
if bytes.HasPrefix(line, []byte(":a")) {
var tripleStmt = line[3:]
triple, err := cquads.Parse(string(tripleStmt))
if !triple.IsValid() {
if err != nil {
fmt.Printf("not a valid triple: %v\n", err)
}
line = line[:0]
continue
}
ts.AddTriple(triple)
line = line[:0]
continue
}
if bytes.HasPrefix(line, []byte(":d")) {
var tripleStmt = line[3:]
triple, err := cquads.Parse(string(tripleStmt))
if !triple.IsValid() {
if err != nil {
fmt.Printf("not a valid triple: %v\n", err)
}
line = line[:0]
continue
}
ts.RemoveTriple(triple)
line = line[:0]
continue
}
result, err := ses.InputParses(string(line))
switch result {
case query.Parsed:
Run(string(line), ses)
line = line[:0]
case query.ParseFail:
fmt.Println("Error: ", err)
line = line[:0]
case query.ParseMore:
}
}
}
开发者ID:jacqui,项目名称:cayley,代码行数:89,代码来源:repl.go
示例4: Repl
func Repl(h *graph.Handle, queryLanguage string, cfg *config.Config) error {
var ses query.Session
switch queryLanguage {
case "sexp":
ses = sexp.NewSession(h.QuadStore)
case "mql":
ses = mql.NewSession(h.QuadStore)
case "gremlin":
fallthrough
default:
ses = gremlin.NewSession(h.QuadStore, cfg.Timeout, true)
}
term, err := terminal(history)
if os.IsNotExist(err) {
fmt.Printf("creating new history file: %q\n", history)
}
defer persist(term, history)
var (
prompt = ps1
code string
)
for {
if len(code) == 0 {
prompt = ps1
} else {
prompt = ps2
}
line, err := term.Prompt(prompt)
if err != nil {
if err == io.EOF {
fmt.Println()
return nil
}
return err
}
term.AppendHistory(line)
line = strings.TrimSpace(line)
if len(line) == 0 || line[0] == '#' {
continue
}
if code == "" {
cmd, args := splitLine(line)
switch cmd {
case ":debug":
args = strings.TrimSpace(args)
var debug bool
switch args {
case "t":
debug = true
case "f":
// Do nothing.
default:
debug, err = strconv.ParseBool(args)
if err != nil {
fmt.Printf("Error: cannot parse %q as a valid boolean - acceptable values: 't'|'true' or 'f'|'false'\n", args)
continue
}
}
ses.Debug(debug)
fmt.Printf("Debug set to %t\n", debug)
continue
case ":a":
quad, err := cquads.Parse(args)
if err != nil {
fmt.Printf("Error: not a valid quad: %v\n", err)
continue
}
h.QuadWriter.WriteQuad(quad)
continue
case ":d":
quad, err := cquads.Parse(args)
if err != nil {
fmt.Printf("Error: not a valid quad: %v\n", err)
continue
}
err = h.QuadWriter.RemoveQuad(quad)
if err != nil {
fmt.Printf("error deleting: %v\n", err)
}
continue
case "exit":
term.Close()
os.Exit(0)
default:
if cmd[0] == ':' {
fmt.Printf("Unknown command: %q\n", cmd)
continue
//.........这里部分代码省略.........
开发者ID:dennwc,项目名称:cayley,代码行数:101,代码来源:repl.go
示例5: Repl
func Repl(h *graph.Handle, queryLanguage string, cfg *config.Config) error {
var ses query.Session
switch queryLanguage {
case "sexp":
ses = sexp.NewSession(h.QuadStore)
case "mql":
ses = mql.NewSession(h.QuadStore)
case "gremlin":
fallthrough
default:
ses = gremlin.NewSession(h.QuadStore, cfg.Timeout, true)
}
term, err := terminal(history)
if os.IsNotExist(err) {
fmt.Printf("creating new history file: %q\n", history)
}
defer persist(term, history)
var (
prompt = ps1
code string
)
for {
if len(code) == 0 {
prompt = ps1
} else {
prompt = ps2
}
line, err := term.Prompt(prompt)
if err != nil {
if err == io.EOF {
fmt.Println()
return nil
}
return err
}
term.AppendHistory(line)
line = strings.TrimSpace(line)
if len(line) == 0 || line[0] == '#' {
continue
}
if code == "" {
switch {
case strings.HasPrefix(line, ":debug"):
ses.ToggleDebug()
fmt.Println("Debug Toggled")
continue
case strings.HasPrefix(line, ":a"):
quad, err := cquads.Parse(line[3:])
if !quad.IsValid() {
if err != nil {
fmt.Printf("not a valid quad: %v\n", err)
}
continue
}
h.QuadWriter.AddQuad(quad)
continue
case strings.HasPrefix(line, ":d"):
quad, err := cquads.Parse(line[3:])
if !quad.IsValid() {
if err != nil {
fmt.Printf("not a valid quad: %v\n", err)
}
continue
}
h.QuadWriter.RemoveQuad(quad)
continue
}
}
code += line
result, err := ses.InputParses(code)
switch result {
case query.Parsed:
Run(code, ses)
code = ""
case query.ParseFail:
fmt.Println("Error: ", err)
code = ""
case query.ParseMore:
}
}
}
开发者ID:JesseLivingston,项目名称:cayley,代码行数:92,代码来源:repl.go
注:本文中的github.com/google/cayley/query.Session类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论