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
|
|
@ -265,7 +265,7 @@ var testQueries = []struct {
|
|||
func runQueryGetTag(g []quad.Quad, query string, tag string) []string {
|
||||
js := makeTestSession(g)
|
||||
c := make(chan interface{}, 5)
|
||||
js.ExecInput(query, c, -1)
|
||||
js.Execute(query, c, -1)
|
||||
|
||||
var results []string
|
||||
for res := range c {
|
||||
|
|
@ -318,7 +318,7 @@ func TestIssue160(t *testing.T) {
|
|||
|
||||
ses := makeTestSession(issue160TestGraph)
|
||||
c := make(chan interface{}, 5)
|
||||
go ses.ExecInput(query, c, 100)
|
||||
go ses.Execute(query, c, 100)
|
||||
var got []string
|
||||
for res := range c {
|
||||
func() {
|
||||
|
|
@ -327,7 +327,7 @@ func TestIssue160(t *testing.T) {
|
|||
t.Errorf("Unexpected panic: %v", r)
|
||||
}
|
||||
}()
|
||||
got = append(got, ses.ToText(res))
|
||||
got = append(got, ses.Format(res))
|
||||
}()
|
||||
}
|
||||
sort.Strings(got)
|
||||
|
|
|
|||
|
|
@ -65,19 +65,21 @@ type Result struct {
|
|||
actualResults map[string]graph.Value
|
||||
}
|
||||
|
||||
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) {
|
||||
// TODO(kortschak) It would be nice to be able
|
||||
// to return an error for bad queries here.
|
||||
s.wk.shape = make(map[string]interface{})
|
||||
s.wk.env.Run(input)
|
||||
out <- s.wk.shape
|
||||
s.wk.env.Run(query)
|
||||
out := s.wk.shape
|
||||
s.wk.shape = nil
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (s *Session) InputParses(input string) (query.ParseResult, error) {
|
||||
func (s *Session) Parse(input string) (query.ParseResult, error) {
|
||||
script, err := s.wk.env.Compile("", input)
|
||||
if err != nil {
|
||||
return query.ParseFail, err
|
||||
|
|
@ -130,7 +132,7 @@ func (s *Session) runUnsafe(input interface{}) (otto.Value, error) {
|
|||
return env.Run(input)
|
||||
}
|
||||
|
||||
func (s *Session) ExecInput(input string, out chan interface{}, _ int) {
|
||||
func (s *Session) Execute(input string, out chan interface{}, _ int) {
|
||||
defer close(out)
|
||||
s.err = nil
|
||||
s.wk.results = out
|
||||
|
|
@ -153,7 +155,7 @@ func (s *Session) ExecInput(input string, out chan interface{}, _ int) {
|
|||
s.wk.Unlock()
|
||||
}
|
||||
|
||||
func (s *Session) ToText(result interface{}) string {
|
||||
func (s *Session) Format(result interface{}) string {
|
||||
data := result.(*Result)
|
||||
if data.metaresult {
|
||||
if data.err != nil {
|
||||
|
|
@ -212,7 +214,7 @@ func (s *Session) ToText(result interface{}) string {
|
|||
}
|
||||
|
||||
// Web stuff
|
||||
func (s *Session) BuildJSON(result interface{}) {
|
||||
func (s *Session) Collate(result interface{}) {
|
||||
data := result.(*Result)
|
||||
if !data.metaresult {
|
||||
if data.val == nil {
|
||||
|
|
@ -246,8 +248,8 @@ func (s *Session) BuildJSON(result interface{}) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *Session) GetJSON() ([]interface{}, error) {
|
||||
defer s.ClearJSON()
|
||||
func (s *Session) Results() (interface{}, error) {
|
||||
defer s.Clear()
|
||||
if s.err != nil {
|
||||
return nil, s.err
|
||||
}
|
||||
|
|
@ -259,6 +261,6 @@ func (s *Session) GetJSON() ([]interface{}, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *Session) ClearJSON() {
|
||||
func (s *Session) Clear() {
|
||||
s.dataOutput = nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue