From a2e06c511db616225a35511028f850cb67cf5f25 Mon Sep 17 00:00:00 2001 From: vird Date: Fri, 1 Jul 2016 09:59:29 +0300 Subject: [PATCH 1/2] Update postgres.js --- lib/postgres.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/postgres.js b/lib/postgres.js index fbe2067..69f0692 100644 --- a/lib/postgres.js +++ b/lib/postgres.js @@ -822,7 +822,7 @@ PG.prototype.propertySettingsSQL = function (model, propName) { // "UNIQUE" could be added here, but it is handled by the indexes code instead! var self = this; var p = self._models[model].properties[propName]; - var result = datatype(p) + ' '; + var result = datatype(p) + (p.size?'('+p.size+')':'') + ' '; if(!propertyCanBeNull.call(self, model, propName)) result = result + 'NOT NULL '; return result; }; @@ -880,6 +880,8 @@ function datatype(p) { case 'double': case 'float': return 'float'; + case 'numeric': + return 'numeric'; case 'integer': default: return 'integer'; From f1c38af1db5644be06e4442dfdeb85c035809056 Mon Sep 17 00:00:00 2001 From: vird Date: Fri, 1 Jul 2016 10:05:24 +0300 Subject: [PATCH 2/2] better impl. --- lib/postgres.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/postgres.js b/lib/postgres.js index 69f0692..93420b9 100644 --- a/lib/postgres.js +++ b/lib/postgres.js @@ -822,7 +822,7 @@ PG.prototype.propertySettingsSQL = function (model, propName) { // "UNIQUE" could be added here, but it is handled by the indexes code instead! var self = this; var p = self._models[model].properties[propName]; - var result = datatype(p) + (p.size?'('+p.size+')':'') + ' '; + var result = datatype(p) + ' '; if(!propertyCanBeNull.call(self, model, propName)) result = result + 'NOT NULL '; return result; }; @@ -868,23 +868,24 @@ function escape(val) { }; function datatype(p) { + var sizeStr = (p.size?'('+p.size+')':''); switch (p.type.name) { default: case 'String': case 'JSON': - return 'varchar'; + return 'varchar'+sizeStr; case 'Text': - return 'text'; + return 'text'+sizeStr; case 'Number': switch (p.dataType) { case 'double': case 'float': - return 'float'; + return 'float'+sizeStr; case 'numeric': - return 'numeric'; + return 'numeric'+sizeStr; case 'integer': default: - return 'integer'; + return 'integer'+sizeStr; } case 'Date': return 'timestamp with time zone';