Document and test "page" and "rows_per_page" parameters.

Closes #123
This commit is contained in:
Sandro Santilli 2013-12-03 10:52:55 -05:00
parent fa4703ccee
commit fcf982e045
2 changed files with 31 additions and 0 deletions

View File

@ -34,6 +34,15 @@ Supported query string parameters:
timestamp value in cache_buster for manual control of timestamp value in cache_buster for manual control of
updates. updates.
'rows_per_page':
Limit the number of rows in output. Affects all formats,
see also 'page'.
'page':
When 'rows_per_page' is used to limit rows, 'page' can be
used to specify which page to start returning rows from.
First page has index 0.
Response formats Response formats
---------------- ----------------

View File

@ -216,6 +216,28 @@ function(done){
}); });
}); });
// Test page and rows_per_page params
test("paging", function(done){
assert.response(app, {
url: '/api/v1/sql?' + querystring.stringify({
// note: select casing intentionally mixed
q: 'SELECT * FROM (VALUES(1),(2),(3),(4),(5),(6),(7),(8),(9)) t(v)',
rows_per_page: 3,
page: 2
}),
headers: {host: 'vizzuality.cartodb.com'},
method: 'GET'
},{ }, function(res) {
assert.equal(res.statusCode, 200, res.body);
var parsed = JSON.parse(res.body);
assert.equal(parsed.rows.length, 3);
assert.equal(parsed.rows[0].v, 7);
assert.equal(parsed.rows[1].v, 8);
assert.equal(parsed.rows[2].v, 9);
done();
});
});
test('POST /api/v1/sql with SQL parameter on SELECT only. no database param, just id using headers', function(done){ test('POST /api/v1/sql with SQL parameter on SELECT only. no database param, just id using headers', function(done){
assert.response(app, { assert.response(app, {
url: '/api/v1/sql', url: '/api/v1/sql',