Make query/... interfaces more idiomatic
Also revert the data type returned by queries to interface{} (the change
made sense at the time).
This commit is contained in:
parent
ad7649806b
commit
21c2d75d07
11 changed files with 304 additions and 299 deletions
|
|
@ -170,11 +170,11 @@ var testQueries = []struct {
|
|||
func runQuery(g []quad.Quad, query string) interface{} {
|
||||
s := makeTestSession(g)
|
||||
c := make(chan interface{}, 5)
|
||||
go s.ExecInput(query, c, -1)
|
||||
go s.Execute(query, c, -1)
|
||||
for result := range c {
|
||||
s.BuildJSON(result)
|
||||
s.Collate(result)
|
||||
}
|
||||
result, _ := s.GetJSON()
|
||||
result, _ := s.Results()
|
||||
return result
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -108,8 +108,6 @@ func (p Path) ToResultPathFromMap(resultMap map[Path]string) ResultPath {
|
|||
func NewQuery(ses *Session) *Query {
|
||||
var q Query
|
||||
q.ses = ses
|
||||
q.results = make([]interface{}, 0)
|
||||
q.resultOrder = make([]string, 0)
|
||||
q.err = nil
|
||||
return &q
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,16 +38,15 @@ func NewSession(qs graph.QuadStore) *Session {
|
|||
return &m
|
||||
}
|
||||
|
||||
func (s *Session) ToggleDebug() {
|
||||
s.debug = !s.debug
|
||||
func (s *Session) Debug(ok bool) {
|
||||
s.debug = ok
|
||||
}
|
||||
|
||||
func (s *Session) GetQuery(input string, out chan map[string]interface{}) {
|
||||
defer close(out)
|
||||
func (s *Session) ShapeOf(query string) (interface{}, error) {
|
||||
var mqlQuery interface{}
|
||||
err := json.Unmarshal([]byte(input), &mqlQuery)
|
||||
err := json.Unmarshal([]byte(query), &mqlQuery)
|
||||
if err != nil {
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
s.currentQuery = NewQuery(s)
|
||||
s.currentQuery.BuildIteratorTree(mqlQuery)
|
||||
|
|
@ -59,10 +58,10 @@ func (s *Session) GetQuery(input string, out chan map[string]interface{}) {
|
|||
nodes = append(nodes, n)
|
||||
}
|
||||
output["nodes"] = nodes
|
||||
out <- output
|
||||
return output, nil
|
||||
}
|
||||
|
||||
func (s *Session) InputParses(input string) (query.ParseResult, error) {
|
||||
func (s *Session) Parse(input string) (query.ParseResult, error) {
|
||||
var x interface{}
|
||||
err := json.Unmarshal([]byte(input), &x)
|
||||
if err != nil {
|
||||
|
|
@ -71,7 +70,7 @@ func (s *Session) InputParses(input string) (query.ParseResult, error) {
|
|||
return query.Parsed, nil
|
||||
}
|
||||
|
||||
func (s *Session) ExecInput(input string, c chan interface{}, _ int) {
|
||||
func (s *Session) Execute(input string, c chan interface{}, _ int) {
|
||||
defer close(c)
|
||||
var mqlQuery interface{}
|
||||
err := json.Unmarshal([]byte(input), &mqlQuery)
|
||||
|
|
@ -104,7 +103,7 @@ func (s *Session) ExecInput(input string, c chan interface{}, _ int) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *Session) ToText(result interface{}) string {
|
||||
func (s *Session) Format(result interface{}) string {
|
||||
tags := result.(map[string]graph.Value)
|
||||
out := fmt.Sprintln("****")
|
||||
tagKeys := make([]string, len(tags))
|
||||
|
|
@ -127,11 +126,11 @@ func (s *Session) ToText(result interface{}) string {
|
|||
return out
|
||||
}
|
||||
|
||||
func (s *Session) BuildJSON(result interface{}) {
|
||||
func (s *Session) Collate(result interface{}) {
|
||||
s.currentQuery.treeifyResult(result.(map[string]graph.Value))
|
||||
}
|
||||
|
||||
func (s *Session) GetJSON() ([]interface{}, error) {
|
||||
func (s *Session) Results() (interface{}, error) {
|
||||
s.currentQuery.buildResults()
|
||||
if s.currentQuery.isError() {
|
||||
return nil, s.currentQuery.err
|
||||
|
|
@ -139,7 +138,7 @@ func (s *Session) GetJSON() ([]interface{}, error) {
|
|||
return s.currentQuery.results, nil
|
||||
}
|
||||
|
||||
func (s *Session) ClearJSON() {
|
||||
func (s *Session) Clear() {
|
||||
// Since we create a new Query underneath every query, clearing isn't necessary.
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue