JSON format: correctly recognize "date" type columns

Closes #117 -- includes testcase
This commit is contained in:
Sandro Santilli 2013-11-06 11:43:56 +01:00
parent 45d54c47cc
commit 0139c8fb16
3 changed files with 11 additions and 6 deletions

View File

@ -1,5 +1,6 @@
1.6.2 - 2013-MM-DD 1.6.2 - 2013-MM-DD
------------------ ------------------
* JSON format: correctly recognize "date" type columns (#117)
1.6.1 - 2013-11-05 1.6.1 - 2013-11-05
------------------ ------------------

View File

@ -63,8 +63,9 @@ var stdTypeName = {
1022: '_float8', 1022: '_float8',
1008: '_regproc', 1008: '_regproc',
1009: '_text', 1009: '_text',
1082: 'date',
1114: 'timestamp', 1114: 'timestamp',
1182: 'date', 1182: '_date',
1184: 'timestampz', 1184: 'timestampz',
1186: 'interval', 1186: 'interval',
1231: '_numeric', 1231: '_numeric',

View File

@ -879,17 +879,19 @@ test('field names and types are exposed', function(done){
assert.response(app, { assert.response(app, {
url: '/api/v1/sql?' + querystring.stringify({ url: '/api/v1/sql?' + querystring.stringify({
q: "SELECT 1::int as a, 2::float8 as b, 3::varchar as c, " + q: "SELECT 1::int as a, 2::float8 as b, 3::varchar as c, " +
"4::char as d, now() as e, 'a'::text as f, " + "4::char as d, now() as e, 'a'::text as f" +
"'POINT(0 0)'::geometry as h " + ", 1::bool as g" +
", 1::bool as g " + ", 'POINT(0 0)'::geometry as h" +
"LIMIT 0" // See https://github.com/CartoDB/CartoDB-SQL-API/issues/117
", now()::date as i" +
" LIMIT 0"
}), }),
headers: {host: 'vizzuality.cartodb.com'}, headers: {host: 'vizzuality.cartodb.com'},
method: 'GET' method: 'GET'
},{ }, function(res) { },{ }, function(res) {
assert.equal(res.statusCode, 200, res.body); assert.equal(res.statusCode, 200, res.body);
var parsedBody = JSON.parse(res.body); var parsedBody = JSON.parse(res.body);
assert.equal(_.keys(parsedBody.fields).length, 8); assert.equal(_.keys(parsedBody.fields).length, 9);
assert.equal(parsedBody.fields.a.type, 'number'); assert.equal(parsedBody.fields.a.type, 'number');
assert.equal(parsedBody.fields.b.type, 'number'); assert.equal(parsedBody.fields.b.type, 'number');
assert.equal(parsedBody.fields.c.type, 'string'); assert.equal(parsedBody.fields.c.type, 'string');
@ -898,6 +900,7 @@ test('field names and types are exposed', function(done){
assert.equal(parsedBody.fields.f.type, 'string'); assert.equal(parsedBody.fields.f.type, 'string');
assert.equal(parsedBody.fields.g.type, 'boolean'); assert.equal(parsedBody.fields.g.type, 'boolean');
assert.equal(parsedBody.fields.h.type, 'geometry'); assert.equal(parsedBody.fields.h.type, 'geometry');
assert.equal(parsedBody.fields.i.type, 'date');
done(); done();
}); });
}); });