From af769488d0e19a79ad9bb4d74cd55711be88f5d1 Mon Sep 17 00:00:00 2001 From: Richard Downe Date: Tue, 8 Aug 2017 20:58:59 -0400 Subject: [PATCH 1/4] use 'REAL' for numeric instead of integer --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 40c9f84..e50135a 100644 --- a/src/index.js +++ b/src/index.js @@ -535,7 +535,7 @@ function propertyToPostgres(property, name, schema, isAlter) { if (property.decimals && property.decimals > 0) { column = 'NUMERIC(' + property.maxLength + ',' + property.decimals + ')'; } else { - column = integerType; + column = 'REAL'; } break; case 'object': From b0ae35bee3777c2e1fb6a73f2245fa0588caf7e5 Mon Sep 17 00:00:00 2001 From: Richard Downe Date: Tue, 22 Aug 2017 15:23:58 -0400 Subject: [PATCH 2/4] since using double, use here, too --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index e50135a..e4ee11f 100644 --- a/src/index.js +++ b/src/index.js @@ -535,7 +535,7 @@ function propertyToPostgres(property, name, schema, isAlter) { if (property.decimals && property.decimals > 0) { column = 'NUMERIC(' + property.maxLength + ',' + property.decimals + ')'; } else { - column = 'REAL'; + column = 'DOUBLE PRECISION'; } break; case 'object': From d94b39081f12ad7183e6fe196aede57fba4e4fb0 Mon Sep 17 00:00:00 2001 From: Richard Downe Date: Mon, 28 Aug 2017 22:15:13 -0400 Subject: [PATCH 3/4] fleshed out the postgresToProperty direction --- src/index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index e4ee11f..3e5dac1 100644 --- a/src/index.js +++ b/src/index.js @@ -22,6 +22,7 @@ function jsonSchemaTable(tableName, schema, config) { } else { dialect.propertyToDb = propertyToPostgres; dialect.bigint = !!config.bigint; + dialect.doubleFloats = !!config.doubleFloats; } return { create: function() { @@ -487,6 +488,7 @@ function mssqlToProperty(metadata) { function propertyToPostgres(property, name, schema, isAlter) { var column; var integerType = this.bigint ? 'BIGINT' : 'INTEGER'; + var floatType = this.doubleFloats ? 'DOUBLE PRECISION' : 'REAL'; switch (property.type) { case 'integer': @@ -535,7 +537,7 @@ function propertyToPostgres(property, name, schema, isAlter) { if (property.decimals && property.decimals > 0) { column = 'NUMERIC(' + property.maxLength + ',' + property.decimals + ')'; } else { - column = 'DOUBLE PRECISION'; + column = floatType; } break; case 'object': @@ -571,10 +573,18 @@ function postgresToProperty(metadata) { var property = {name: metadata.column_name}; switch (metadata.data_type) { case 'integer': + case 'boolean': case 'text': case 'date': property.type = metadata.data_type; break; + case 'bigint': + property.type = 'integer'; + break; + case 'real': + case 'double precision': + property.type = 'numeric'; + break; case 'time': property.type = 'time'; property.timezone = 'ignore'; From 4114af7cf4b274898e9e07e6cf6b91b4d3c94d0a Mon Sep 17 00:00:00 2001 From: Richard Downe Date: Tue, 29 Aug 2017 22:13:22 -0400 Subject: [PATCH 4/4] fixes to compatibility issues --- src/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 3e5dac1..84735eb 100644 --- a/src/index.js +++ b/src/index.js @@ -536,6 +536,8 @@ function propertyToPostgres(property, name, schema, isAlter) { case 'number': if (property.decimals && property.decimals > 0) { column = 'NUMERIC(' + property.maxLength + ',' + property.decimals + ')'; + } else if (property.maxLength > 0) { + column = integerType; } else { column = floatType; } @@ -583,7 +585,7 @@ function postgresToProperty(metadata) { break; case 'real': case 'double precision': - property.type = 'numeric'; + property.type = 'number'; break; case 'time': property.type = 'time';