diff --git a/db/repl.go b/db/repl.go index 770fb33..fa5e447 100644 --- a/db/repl.go +++ b/db/repl.go @@ -66,7 +66,7 @@ func Repl(ts graph.TripleStore, queryLanguage string, cfg *config.Config) { case "sexp": ses = sexp.NewSexpSession(ts) case "mql": - ses = mql.NewMqlSession(ts) + ses = mql.NewSession(ts) case "gremlin": fallthrough default: diff --git a/http/query.go b/http/query.go index da11b7f..683e3d5 100644 --- a/http/query.go +++ b/http/query.go @@ -73,7 +73,7 @@ func (api *Api) ServeV1Query(w http.ResponseWriter, r *http.Request, params http case "gremlin": ses = gremlin.NewSession(api.ts, api.config.GremlinTimeout, false) case "mql": - ses = mql.NewMqlSession(api.ts) + ses = mql.NewSession(api.ts) default: return FormatJson400(w, "Need a query language.") } @@ -122,7 +122,7 @@ func (api *Api) ServeV1Shape(w http.ResponseWriter, r *http.Request, params http case "gremlin": ses = gremlin.NewSession(api.ts, api.config.GremlinTimeout, false) case "mql": - ses = mql.NewMqlSession(api.ts) + ses = mql.NewSession(api.ts) default: return FormatJson400(w, "Need a query language.") } diff --git a/query/mql/functional_test.go b/query/mql/functional_test.go index 97c2eac..e814574 100644 --- a/query/mql/functional_test.go +++ b/query/mql/functional_test.go @@ -35,9 +35,9 @@ import ( // +---+ // -func buildTripleStore() *MqlSession { +func buildTripleStore() *Session { ts := memstore.MakeTestingMemstore() - return NewMqlSession(ts) + return NewSession(ts) } func compareJsonInterfaces(actual interface{}, expected interface{}, path MqlPath, t *testing.T) { diff --git a/query/mql/query.go b/query/mql/query.go index 66d8179..c52bb28 100644 --- a/query/mql/query.go +++ b/query/mql/query.go @@ -25,7 +25,7 @@ type MqlPath string type MqlResultPath string type MqlQuery struct { - ses *MqlSession + ses *Session it graph.Iterator isRepeated map[MqlPath]bool queryStructure map[MqlPath]map[string]interface{} @@ -100,7 +100,7 @@ func (p MqlPath) ToResultPathFromMap(resultMap map[MqlPath]string) MqlResultPath return output } -func NewMqlQuery(ses *MqlSession) *MqlQuery { +func NewMqlQuery(ses *Session) *MqlQuery { var q MqlQuery q.ses = ses q.results = make([]interface{}, 0) diff --git a/query/mql/session.go b/query/mql/session.go index 96d88bf..8565581 100644 --- a/query/mql/session.go +++ b/query/mql/session.go @@ -24,23 +24,23 @@ import ( "github.com/google/cayley/graph" ) -type MqlSession struct { +type Session struct { ts graph.TripleStore currentQuery *MqlQuery debug bool } -func NewMqlSession(ts graph.TripleStore) *MqlSession { - var m MqlSession +func NewSession(ts graph.TripleStore) *Session { + var m Session m.ts = ts return &m } -func (m *MqlSession) ToggleDebug() { +func (m *Session) ToggleDebug() { m.debug = !m.debug } -func (m *MqlSession) GetQuery(input string, output_struct chan map[string]interface{}) { +func (m *Session) GetQuery(input string, output_struct chan map[string]interface{}) { defer close(output_struct) var mqlQuery interface{} err := json.Unmarshal([]byte(input), &mqlQuery) @@ -61,7 +61,7 @@ func (m *MqlSession) GetQuery(input string, output_struct chan map[string]interf output_struct <- output } -func (m *MqlSession) InputParses(input string) (graph.ParseResult, error) { +func (m *Session) InputParses(input string) (graph.ParseResult, error) { var x interface{} err := json.Unmarshal([]byte(input), &x) if err != nil { @@ -70,7 +70,7 @@ func (m *MqlSession) InputParses(input string) (graph.ParseResult, error) { return graph.Parsed, nil } -func (m *MqlSession) ExecInput(input string, c chan interface{}, limit int) { +func (m *Session) ExecInput(input string, c chan interface{}, limit int) { defer close(c) var mqlQuery interface{} err := json.Unmarshal([]byte(input), &mqlQuery) @@ -102,7 +102,7 @@ func (m *MqlSession) ExecInput(input string, c chan interface{}, limit int) { } } -func (m *MqlSession) ToText(result interface{}) string { +func (m *Session) ToText(result interface{}) string { tags := *(result.(*map[string]graph.TSVal)) out := fmt.Sprintln("****") tagKeys := make([]string, len(tags)) @@ -125,11 +125,11 @@ func (m *MqlSession) ToText(result interface{}) string { return out } -func (m *MqlSession) BuildJson(result interface{}) { +func (m *Session) BuildJson(result interface{}) { m.currentQuery.treeifyResult(*(result.(*map[string]graph.TSVal))) } -func (m *MqlSession) GetJson() (interface{}, error) { +func (m *Session) GetJson() (interface{}, error) { m.currentQuery.buildResults() if m.currentQuery.isError { return nil, m.currentQuery.err @@ -138,7 +138,7 @@ func (m *MqlSession) GetJson() (interface{}, error) { } } -func (m *MqlSession) ClearJson() { +func (m *Session) ClearJson() { // Since we create a new MqlQuery underneath every query, clearing isn't necessary. return }