@@ -51,6 +51,7 @@ module.exports = {
51
51
example : [ {
52
52
fieldName : 'birthday' ,
53
53
type : 'string' , // number, string, boolean, dictionary, or array
54
+ dbType : 'timezone with timestamp' ,
54
55
indexed : true ,
55
56
unique : true ,
56
57
primaryKey : false ,
@@ -76,7 +77,7 @@ module.exports = {
76
77
var query = "SELECT x.nspname || '.' || x.relname as \"Table\", x.attnum as \"#\", x.attname as \"Column\", x.\"Type\"," +
77
78
" case x.attnotnull when true then 'NOT NULL' else '' end as \"NULL\", r.conname as \"Constraint\", r.contype as \"C\", " +
78
79
"r.consrc, fn.nspname || '.' || f.relname as \"F Key\", d.adsrc as \"Default\" FROM (" +
79
- "SELECT c.oid, a.attrelid, a.attnum, n.nspname, c.relname, a.attname, pg_catalog.format_type(a.atttypid, a.atttypmod ) as \"Type\", " +
80
+ "SELECT c.oid, a.attrelid, a.attnum, n.nspname, c.relname, a.attname, pg_catalog.format_type(a.atttypid, null ) as \"Type\", " +
80
81
"a.attnotnull FROM pg_catalog.pg_attribute a, pg_namespace n, pg_class c WHERE a.attnum > 0 AND NOT a.attisdropped AND a.attrelid = c.oid " +
81
82
"and c.relkind not in ('S','v') and c.relnamespace = n.oid and n.nspname not in ('pg_catalog','pg_toast','information_schema')) x " +
82
83
"left join pg_attrdef d on d.adrelid = x.attrelid and d.adnum = x.attnum " +
@@ -173,7 +174,65 @@ module.exports = {
173
174
obj . fieldName = column . Column ;
174
175
175
176
// Set Type
176
- obj . type = column . Type ;
177
+ switch ( column . Type ) {
178
+
179
+ // Number types
180
+ case 'smallint' :
181
+ case 'integer' :
182
+ case 'bigint' :
183
+ case 'decimal' :
184
+ case 'numeric' :
185
+ case 'real' :
186
+ case 'double precision' :
187
+ case 'smallserial' :
188
+ case 'bigserial' :
189
+ obj . type = 'number' ;
190
+ break ;
191
+
192
+ // String types
193
+ case 'character' :
194
+ case 'char' :
195
+ case 'varchar' :
196
+ case 'character varying' :
197
+ case 'text' :
198
+ obj . type = 'string' ;
199
+ break ;
200
+
201
+ // Date types
202
+ case 'timestamp' :
203
+ case 'timestamp without time zone' :
204
+ case 'timestamp with time zone' :
205
+ case 'time' :
206
+ case 'time without time zone' :
207
+ case 'time with time zone' :
208
+ case 'date' :
209
+ case 'interval' :
210
+ obj . type = 'string' ;
211
+ break ;
212
+
213
+ // Boolean type
214
+ case 'boolean' :
215
+ obj . type = 'boolean' ;
216
+ break ;
217
+
218
+ // JSON type
219
+ case 'json' :
220
+ obj . type = 'dictionary' ;
221
+ break ;
222
+
223
+ // Array types
224
+ case 'array' :
225
+ obj . type = 'array' ;
226
+ break ;
227
+
228
+ // Everything else make a string
229
+ default :
230
+ obj . type = 'string' ;
231
+ break ;
232
+ } ;
233
+
234
+ // Store the original db type as well
235
+ obj . dbType = column . Type ;
177
236
178
237
// Check for index
179
238
if ( column . indexed ) {
0 commit comments