diff --git a/core/http.go b/core/http.go index 43ba2ca2b..a48ace718 100644 --- a/core/http.go +++ b/core/http.go @@ -65,17 +65,19 @@ func (self *WebService) HandleQuery(w http.ResponseWriter, r *http.Request) { } database_name := r.Form.Get("db") - pql := r.Form.Get("pql") - - defer r.Body.Close() - if pql == "" { - http.Error(w, "Error reading POST data", http.StatusBadRequest) + if database_name == "" { + database_name = config.GetString("default_db") + } + if database_name == "" { + http.Error(w, "Provide a database (db)", http.StatusNotFound) return } - // TODO: we need to get the database name from the query string (for now, hard-coded) - if database_name == "" { - database_name = "main" //TODO pull this from config DEFAULT + pql := r.Form.Get("pql") + if pql == "" { + http.Error(w, "Provide a valid query string (pql)", http.StatusNotFound) + return } + results := self.service.Executor.RunPQL(database_name, pql) encoder := json.NewEncoder(w) diff --git a/executor/executor.go b/executor/executor.go index f421e7d0c..9e07b9261 100644 --- a/executor/executor.go +++ b/executor/executor.go @@ -103,10 +103,10 @@ func (self *Executor) RunPQL(database_name string, pql string) interface{} { return final } else { - macros_dir := config.GetString("macros") - macros_file := macros_dir + "/" + outer_token + ".js" + plugins_dir := config.GetString("plugins") + plugins_file := plugins_dir + "/" + outer_token + ".js" filter := query.TokensToString(tokens) - query_list := GetMacro(macros_file, filter).(query.PqlList) + query_list := GetMacro(plugins_file, filter).(query.PqlList) for i, _ := range query_list { qry := query.QueryForPQL(query_list[i].PQL) diff --git a/executor/utils.go b/executor/utils.go index d6a989793..c308638ef 100644 --- a/executor/utils.go +++ b/executor/utils.go @@ -16,7 +16,7 @@ func GetMacro(file_name string, filter string) interface{} { } s := string(file_data[:]) - js := "query_list = (function (filter){" + s + "})('" + filter + "');" + js := "query_list = (" + s + ")('" + filter + "');" Otto := otto.New() Otto.Run(js)