To run SQL like query for tables, streams etc. we can use the following API:

Method : GET

URI : /db/<dbname>/table

Body

{
    "sql":"select * from ...",
    "levk":"abcd",
    "sec_buf":"",
    "rev_buf":"",
    "switch_done":1
}

BangDB returns around 4MB of data in one shot (this is configurable, but still a limited data in one call), which means if there are more data in the table for the same query then I need to call again. But in next call I would like to start from right where it stopped. This becomes complicated when the query contains filter clauses for secondary or reverse indexes.

BangDB abstracts all these details and helps users with just few key/value pairs that it returns along with response. And in subsequent call, we just need to copy paste those key/value pairs along with the "sql" query and call the API again to get the next set of data. We can keep doing this until data is exhausted in the db or we don't wish to call again. Let's see all the attributes here in the json body.

"sql" : put your sql query here

If in response we see “more_data_to_come” as 1 , then it means we have more data in the table for the query and we need to call it again. This time we will copy whatever other attribute is there in the request json doc as they are (no need to copy "more_data_to_come") along with the original sql query

Example

curl -H "Content-Type: application/json" -d '{"sql": "select * from my_table_test"}' -X POST http://192.168.1.105:18080/db/mydb/query

Response

{
   "rows":[
      {
         "k":"user1",
         "v":"{\"name\":\"sachin sinha\", \"org\":\"BangDB\", \"likes\":[\"music\",\"cricket\",\"linux\",\"coding\"],\"_pk\":\"user1\",\"_v\":1}"
      },
      {
         "k":"user2",
         "v":"{\"name\":\"Andy B\", \"org\":\"BangDB\", \"likes\":[\"books\",\"mountains\",\"system designs\"],\"_pk\":\"user2\",\"_v\":1}"
      }
   ],
   "num_items":2,
   "more_data_to_come":0,
   "switch_done":0
}

As you see here, the response has variable "more_data_to_come" which is set as 0, which means we have retrieved all the data for the query and no need to call the API again.

Table APIs : All table APIs start with /db/<dbname>/<tablename>