3
3
// This file is licensed under the Artistic License 2.0.
4
4
// License text available at https://opensource.org/licenses/Artistic-2.0
5
5
6
+ 'use strict' ;
6
7
var g = require ( 'strong-globalize' ) ( ) ;
7
8
8
9
module . exports = mixinDiscovery ;
@@ -56,7 +57,6 @@ function mixinDiscovery(PostgreSQL) {
56
57
function queryViews ( options ) {
57
58
var sqlViews = null ;
58
59
if ( options . views ) {
59
-
60
60
var owner = options . owner || options . schema ;
61
61
62
62
if ( options . all && ! owner ) {
@@ -82,24 +82,24 @@ function mixinDiscovery(PostgreSQL) {
82
82
* @param {Object } options Options for discovery
83
83
* @param {Function } [cb] The callback function
84
84
*/
85
- PostgreSQL . prototype . discoverModelDefinitions = function ( options , cb ) {
85
+ PostgreSQL . prototype . discoverModelDefinitions = function ( options , cb ) {
86
86
if ( ! cb && typeof options === 'function' ) {
87
87
cb = options ;
88
88
options = { } ;
89
89
}
90
90
options = options || { } ;
91
91
92
92
var self = this ;
93
- var calls = [ function ( callback ) {
93
+ var calls = [ function ( callback ) {
94
94
self . execute ( queryTables ( options ) , callback ) ;
95
95
} ] ;
96
96
97
97
if ( options . views ) {
98
- calls . push ( function ( callback ) {
98
+ calls . push ( function ( callback ) {
99
99
self . execute ( queryViews ( options ) , callback ) ;
100
100
} ) ;
101
101
}
102
- async . parallel ( calls , function ( err , data ) {
102
+ async . parallel ( calls , function ( err , data ) {
103
103
if ( err ) {
104
104
cb ( err , data ) ;
105
105
} else {
@@ -135,7 +135,7 @@ function mixinDiscovery(PostgreSQL) {
135
135
owner : options . owner || options . schema ,
136
136
table : table ,
137
137
options : options ,
138
- cb : cb
138
+ cb : cb ,
139
139
} ;
140
140
}
141
141
@@ -148,15 +148,17 @@ function mixinDiscovery(PostgreSQL) {
148
148
function queryColumns ( owner , table ) {
149
149
var sql = null ;
150
150
if ( owner ) {
151
- sql = paginateSQL ( 'SELECT table_schema AS "owner", table_name AS "tableName", column_name AS "columnName", data_type AS "dataType",'
152
- + ' character_maximum_length AS "dataLength", numeric_precision AS "dataPrecision", numeric_scale AS "dataScale", is_nullable AS "nullable"'
151
+ sql = paginateSQL ( 'SELECT table_schema AS "owner", table_name AS "tableName", column_name AS "columnName",'
152
+ + 'data_type AS "dataType", character_maximum_length AS "dataLength", numeric_precision AS "dataPrecision",'
153
+ + ' numeric_scale AS "dataScale", is_nullable AS "nullable"'
153
154
+ ' FROM information_schema.columns'
154
155
+ ' WHERE table_schema=\'' + owner + '\''
155
156
+ ( table ? ' AND table_name=\'' + table + '\'' : '' ) ,
156
157
'table_name, ordinal_position' , { } ) ;
157
158
} else {
158
- sql = paginateSQL ( 'SELECT current_schema() AS "owner", table_name AS "tableName", column_name AS "columnName", data_type AS "dataType",'
159
- + ' character_maximum_length AS "dataLength", numeric_precision AS "dataPrecision", numeric_scale AS "dataScale", is_nullable AS "nullable"'
159
+ sql = paginateSQL ( 'SELECT current_schema() AS "owner", table_name AS "tableName", column_name AS "columnName",'
160
+ + ' data_type AS "dataType", character_maximum_length AS "dataLength", numeric_precision AS "dataPrecision",'
161
+ + ' numeric_scale AS "dataScale", is_nullable AS "nullable"'
160
162
+ ' FROM information_schema.columns'
161
163
+ ( table ? ' WHERE table_name=\'' + table + '\'' : '' ) ,
162
164
'table_name, ordinal_position' , { } ) ;
@@ -171,19 +173,19 @@ function mixinDiscovery(PostgreSQL) {
171
173
* @param {Function } [cb] The callback function
172
174
*
173
175
*/
174
- PostgreSQL . prototype . discoverModelProperties = function ( table , options , cb ) {
176
+ PostgreSQL . prototype . discoverModelProperties = function ( table , options , cb ) {
175
177
var args = getArgs ( table , options , cb ) ;
176
178
var owner = args . owner ;
177
179
table = args . table ;
178
180
options = args . options ;
179
181
cb = args . cb ;
180
182
181
183
var sql = queryColumns ( owner , table ) ;
182
- var callback = function ( err , results ) {
184
+ var callback = function ( err , results ) {
183
185
if ( err ) {
184
186
cb ( err , results ) ;
185
187
} else {
186
- results . map ( function ( r ) {
188
+ results . map ( function ( r ) {
187
189
r . type = mysqlDataTypeToJSONType ( r . dataType , r . dataLength ) ;
188
190
} ) ;
189
191
cb ( err , results ) ;
@@ -192,7 +194,6 @@ function mixinDiscovery(PostgreSQL) {
192
194
this . execute ( sql , callback ) ;
193
195
} ;
194
196
195
-
196
197
// http://docs.oracle.com/javase/6/docs/api/java/sql/DatabaseMetaData.html#getPrimaryKeys(java.lang.String, java.lang.String, java.lang.String)
197
198
198
199
/*
@@ -238,7 +239,7 @@ function mixinDiscovery(PostgreSQL) {
238
239
* @param {Object } options The options for discovery
239
240
* @param {Function } [cb] The callback function
240
241
*/
241
- PostgreSQL . prototype . discoverPrimaryKeys = function ( table , options , cb ) {
242
+ PostgreSQL . prototype . discoverPrimaryKeys = function ( table , options , cb ) {
242
243
var args = getArgs ( table , options , cb ) ;
243
244
var owner = args . owner ;
244
245
table = args . table ;
@@ -296,7 +297,7 @@ function mixinDiscovery(PostgreSQL) {
296
297
* @param {Object } options The options for discovery
297
298
* @param {Function } [cb] The callback function
298
299
*/
299
- PostgreSQL . prototype . discoverForeignKeys = function ( table , options , cb ) {
300
+ PostgreSQL . prototype . discoverForeignKeys = function ( table , options , cb ) {
300
301
var args = getArgs ( table , options , cb ) ;
301
302
var owner = args . owner ;
302
303
table = args . table ;
@@ -341,7 +342,7 @@ function mixinDiscovery(PostgreSQL) {
341
342
* @param {Object } options The options for discovery
342
343
* @param {Function } [cb] The callback function
343
344
*/
344
- PostgreSQL . prototype . discoverExportedForeignKeys = function ( table , options , cb ) {
345
+ PostgreSQL . prototype . discoverExportedForeignKeys = function ( table , options , cb ) {
345
346
var args = getArgs ( table , options , cb ) ;
346
347
var owner = args . owner ;
347
348
table = args . table ;
@@ -385,21 +386,19 @@ function mixinDiscovery(PostgreSQL) {
385
386
}
386
387
}
387
388
388
-
389
389
/**
390
390
* Discover database indexes for the specified table
391
391
* @param {String } table The table name
392
392
* @param {Function } [cb] The callback function
393
393
*/
394
- PostgreSQL . prototype . discoverModelIndexes = function ( model , cb ) {
394
+ PostgreSQL . prototype . discoverModelIndexes = function ( model , cb ) {
395
395
this . getTableStatus ( model , function ( err , fields , indexes ) {
396
396
var indexData = { } ;
397
- indexes . forEach ( function ( index ) {
397
+ indexes . forEach ( function ( index ) {
398
398
indexData [ index . name ] = index ;
399
399
delete index . name ;
400
400
} ) ;
401
401
cb ( err , indexData ) ;
402
402
} ) ;
403
- }
404
-
403
+ } ;
405
404
}
0 commit comments