1
0
Fork 0

Merge branch 'hrqlite'

master
Philip O Toole 9 years ago
commit fc9147a989

@ -45,18 +45,18 @@ All responses from rqlite are in the form of JSON.
### Writing Data
To write data successfully to the database, you must create at least 1 table. To do this, perform a HTTP POST, with a CREATE TABLE SQL command encapsulated in a JSON array, in the body of the request. For example:
curl -L -XPOST localhost:4001/db?pretty -d '[
curl -L -XPOST localhost:4001/db?pretty-H "Content-Type: application/json" -d '[
"CREATE TABLE foo (id integer not null primary key, name text)"
]'
where `curl` is the [well known command-line tool](http://curl.haxx.se/). Passing `-L` to `curl` ensures the command will follow any redirect (HTTP status code 307) to the leader, if the node running on port 4001 is not the leader.
where `curl` is the [well known command-line tool](http://curl.haxx.se/). Passing `-L` to `curl` ensures the command will follow any redirect (HTTP status code 307) to the leader, if the node running on port 4001 is not the leader. It is *very important* to set the `Content-Type` header as shown.
To insert an entry into the database, execute a second SQL command:
curl -L -XPOST 'localhost:4001/db?pretty&explain' -d '[
curl -L -XPOST 'localhost:4001/db?pretty&explain' -H "Content-Type: application/json" -d '[
"INSERT INTO foo(name) VALUES(\"fiona\")"
]'
The response is of the form:
[{"last_insert_id":1,"rows_affected":1}]
@ -77,7 +77,7 @@ Note that this is the SQLite file that is under `node 3`, which is not the node
### Bulk Updates
Bulk updates are supported. To execute multipe statements in one HTTP call, simply include the statements in the JSON array:
curl -L -XPOST 'localhost:4001/db?pretty' -d '[
curl -L -XPOST 'localhost:4001/db?pretty' -H "Content-Type: application/json" -d '[
"INSERT INTO foo(name) VALUES(\"fiona\")",
"INSERT INTO foo(name) VALUES(\"sinead\")"
]'
@ -91,7 +91,7 @@ The response is of the form:
Transactions are supported. To execute statements within a transaction, add `transaction` to the URL. An example of the above operation executed within a transaction is shown below.
curl -L -XPOST 'localhost:4001/db?pretty&transaction' -d '[
curl -L -XPOST 'localhost:4001/db?pretty&transaction' -H "Content-Type: application/json" -d '[
"INSERT INTO foo(name) VALUES(\"fiona\")",
"INSERT INTO foo(name) VALUES(\"sinead\")""
]'
@ -128,7 +128,7 @@ The response is of the form:
The behaviour of rqlite when more than 1 query is passed via `q` is undefined. If you want to execute more than one query per HTTP request, place the queries in the body of the request, as a JSON array. For example:
curl -L -G 'localhost:4001/db?pretty' -d '[
curl -L -G 'localhost:4001/db?pretty' -H "Content-Type: application/json" -d '[
"SELECT * FROM foo",
"SELECT * FROM bar"
]'

@ -125,11 +125,11 @@ func (s *Service) handleJoin(w http.ResponseWriter, r *http.Request) {
// handleExecute handles queries that modify the database.
func (s *Service) handleExecute(w http.ResponseWriter, r *http.Request) {
// isTx, err := isTx(r)
// if err != nil {
// w.WriteHeader(http.StatusInternalServerError)
// return
// }
isTx, err := isTx(r)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
b, err := ioutil.ReadAll(r.Body)
if err != nil {
@ -144,7 +144,7 @@ func (s *Service) handleExecute(w http.ResponseWriter, r *http.Request) {
return
}
results, err := s.store.Execute(queries, false)
results, err := s.store.Execute(queries, isTx)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
@ -168,17 +168,11 @@ func (s *Service) handleExecute(w http.ResponseWriter, r *http.Request) {
// handleQuery handles queries that do not modify the database.
func (s *Service) handleQuery(w http.ResponseWriter, r *http.Request) {
// isLeader, err := isLeader(r)
// if err != nil {
// w.WriteHeader(http.StatusInternalServerError)
// return
// }
// isTx, err := isTx(r)
// if err != nil {
// w.WriteHeader(http.StatusInternalServerError)
// return
// }
isTx, err := isTx(r)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
// Get the query statement, check leader and do tx if necessary.
query, err := stmtParam(r)
@ -187,7 +181,7 @@ func (s *Service) handleQuery(w http.ResponseWriter, r *http.Request) {
return
}
rows, err := s.store.Query([]string{query}, false)
rows, err := s.store.Query([]string{query}, isTx)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return

Loading…
Cancel
Save