|
|
@ -122,39 +122,17 @@ func (n *Node) ExecuteQueuedMulti(stmts []string, wait bool) (string, error) {
|
|
|
|
|
|
|
|
|
|
|
|
// Query runs a single query against the node.
|
|
|
|
// Query runs a single query against the node.
|
|
|
|
func (n *Node) Query(stmt string) (string, error) {
|
|
|
|
func (n *Node) Query(stmt string) (string, error) {
|
|
|
|
v, _ := url.Parse("http://" + n.APIAddr + "/db/query")
|
|
|
|
return n.query(stmt, "weak")
|
|
|
|
v.RawQuery = url.Values{"q": []string{stmt}}.Encode()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resp, err := http.Get(v.String())
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return "", err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
body, err := ioutil.ReadAll(resp.Body)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return "", err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return string(body), nil
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// QueryNoneConsistency runs a single query against the node, with no read consistency.
|
|
|
|
// QueryNoneConsistency runs a single query against the node, with no read consistency.
|
|
|
|
func (n *Node) QueryNoneConsistency(stmt string) (string, error) {
|
|
|
|
func (n *Node) QueryNoneConsistency(stmt string) (string, error) {
|
|
|
|
v, _ := url.Parse("http://" + n.APIAddr + "/db/query")
|
|
|
|
return n.query(stmt, "none")
|
|
|
|
v.RawQuery = url.Values{
|
|
|
|
}
|
|
|
|
"q": []string{stmt},
|
|
|
|
|
|
|
|
"level": []string{"none"},
|
|
|
|
|
|
|
|
}.Encode()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resp, err := http.Get(v.String())
|
|
|
|
// QueryStrongConsistency runs a single query against the node, with Strong read consistency.
|
|
|
|
if err != nil {
|
|
|
|
func (n *Node) QueryStrongConsistency(stmt string) (string, error) {
|
|
|
|
return "", err
|
|
|
|
return n.query(stmt, "strong")
|
|
|
|
}
|
|
|
|
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
body, err := ioutil.ReadAll(resp.Body)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return "", err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return string(body), nil
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// QueryMulti runs multiple queries against the node.
|
|
|
|
// QueryMulti runs multiple queries against the node.
|
|
|
@ -386,6 +364,25 @@ func (n *Node) postExecuteQueued(stmt string, wait bool) (string, error) {
|
|
|
|
return string(body), nil
|
|
|
|
return string(body), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (n *Node) query(stmt, consistency string) (string, error) {
|
|
|
|
|
|
|
|
v, _ := url.Parse("http://" + n.APIAddr + "/db/query")
|
|
|
|
|
|
|
|
v.RawQuery = url.Values{
|
|
|
|
|
|
|
|
"q": []string{stmt},
|
|
|
|
|
|
|
|
"level": []string{consistency},
|
|
|
|
|
|
|
|
}.Encode()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resp, err := http.Get(v.String())
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return "", err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
body, err := ioutil.ReadAll(resp.Body)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return "", err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return string(body), nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (n *Node) postQuery(stmt string) (string, error) {
|
|
|
|
func (n *Node) postQuery(stmt string) (string, error) {
|
|
|
|
resp, err := http.Post("http://"+n.APIAddr+"/db/query", "application/json", strings.NewReader(stmt))
|
|
|
|
resp, err := http.Post("http://"+n.APIAddr+"/db/query", "application/json", strings.NewReader(stmt))
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|