From 0139c8fb1636b0a0cb7c799ab4b2e73d6dfddb97 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Wed, 6 Nov 2013 11:43:56 +0100 Subject: [PATCH] JSON format: correctly recognize "date" type columns Closes #117 -- includes testcase --- NEWS.md | 1 + app/models/psql.js | 3 ++- test/acceptance/app.test.js | 13 ++++++++----- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/NEWS.md b/NEWS.md index 2a40d132..33d27e6c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ 1.6.2 - 2013-MM-DD ------------------ +* JSON format: correctly recognize "date" type columns (#117) 1.6.1 - 2013-11-05 ------------------ diff --git a/app/models/psql.js b/app/models/psql.js index 20506cac..9c77ed90 100644 --- a/app/models/psql.js +++ b/app/models/psql.js @@ -63,8 +63,9 @@ var stdTypeName = { 1022: '_float8', 1008: '_regproc', 1009: '_text', + 1082: 'date', 1114: 'timestamp', - 1182: 'date', + 1182: '_date', 1184: 'timestampz', 1186: 'interval', 1231: '_numeric', diff --git a/test/acceptance/app.test.js b/test/acceptance/app.test.js index a22ebdb2..ba3181c1 100644 --- a/test/acceptance/app.test.js +++ b/test/acceptance/app.test.js @@ -879,17 +879,19 @@ test('field names and types are exposed', function(done){ assert.response(app, { url: '/api/v1/sql?' + querystring.stringify({ 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, " + - "'POINT(0 0)'::geometry as h " + - ", 1::bool as g " + - "LIMIT 0" + "4::char as d, now() as e, 'a'::text as f" + + ", 1::bool as g" + + ", 'POINT(0 0)'::geometry as h" + + // See https://github.com/CartoDB/CartoDB-SQL-API/issues/117 + ", now()::date as i" + + " LIMIT 0" }), headers: {host: 'vizzuality.cartodb.com'}, method: 'GET' },{ }, function(res) { assert.equal(res.statusCode, 200, 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.b.type, 'number'); 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.g.type, 'boolean'); assert.equal(parsedBody.fields.h.type, 'geometry'); + assert.equal(parsedBody.fields.i.type, 'date'); done(); }); });