44// License text available at https://opensource.org/licenses/Artistic-2.0
55
66'use strict' ;
7- var g = require ( 'strong-globalize' ) ( ) ;
7+ const g = require ( 'strong-globalize' ) ( ) ;
88
99module . exports = mixinDiscovery ;
1010
1111function mixinDiscovery ( PostgreSQL ) {
12- var async = require ( 'async' ) ;
12+ const async = require ( 'async' ) ;
1313
1414 PostgreSQL . prototype . paginateSQL = function ( sql , orderBy , options ) {
1515 options = options || { } ;
16- var limit = '' ;
16+ let limit = '' ;
1717 if ( options . offset || options . skip || options . limit ) {
1818 limit = ' OFFSET ' + ( options . offset || options . skip || 0 ) ; // Offset starts from 0
1919 if ( options . limit ) {
@@ -32,8 +32,8 @@ function mixinDiscovery(PostgreSQL) {
3232 * @returns {string } The sql statement
3333 */
3434 PostgreSQL . prototype . buildQueryTables = function ( options ) {
35- var sqlTables = null ;
36- var owner = options . owner || options . schema ;
35+ let sqlTables = null ;
36+ const owner = options . owner || options . schema ;
3737
3838 if ( options . all && ! owner ) {
3939 sqlTables = this . paginateSQL ( 'SELECT \'table\' AS "type", table_name AS "name", table_schema AS "owner"'
@@ -44,7 +44,7 @@ function mixinDiscovery(PostgreSQL) {
4444 } else {
4545 sqlTables = this . paginateSQL ( 'SELECT \'table\' AS "type", table_name AS "name",'
4646 + ' table_schema AS "owner" FROM information_schema.tables WHERE table_schema=current_schema()' ,
47- 'table_name' , options ) ;
47+ 'table_name' , options ) ;
4848 }
4949 return sqlTables ;
5050 } ;
@@ -55,22 +55,22 @@ function mixinDiscovery(PostgreSQL) {
5555 * @returns {string } The sql statement
5656 */
5757 PostgreSQL . prototype . buildQueryViews = function ( options ) {
58- var sqlViews = null ;
58+ let sqlViews = null ;
5959 if ( options . views ) {
60- var owner = options . owner || options . schema ;
60+ const owner = options . owner || options . schema ;
6161
6262 if ( options . all && ! owner ) {
6363 sqlViews = this . paginateSQL ( 'SELECT \'view\' AS "type", table_name AS "name",'
6464 + ' table_schema AS "owner" FROM information_schema.views' ,
65- 'table_schema, table_name' , options ) ;
65+ 'table_schema, table_name' , options ) ;
6666 } else if ( owner ) {
6767 sqlViews = this . paginateSQL ( 'SELECT \'view\' AS "type", table_name AS "name",'
6868 + ' table_schema AS "owner" FROM information_schema.views WHERE table_schema=\'' + owner + '\'' ,
69- 'table_schema, table_name' , options ) ;
69+ 'table_schema, table_name' , options ) ;
7070 } else {
7171 sqlViews = this . paginateSQL ( 'SELECT \'view\' AS "type", table_name AS "name",'
7272 + ' current_schema() AS "owner" FROM information_schema.views' ,
73- 'table_name' , options ) ;
73+ 'table_name' , options ) ;
7474 }
7575 }
7676 return sqlViews ;
@@ -117,9 +117,9 @@ function mixinDiscovery(PostgreSQL) {
117117 * @param {Function } [cb] The callback function
118118 */
119119 PostgreSQL . prototype . discoverModelProperties = function ( table , options , cb ) {
120- var self = this ;
121- var args = self . getArgs ( table , options , cb ) ;
122- var schema = args . schema ;
120+ const self = this ;
121+ const args = self . getArgs ( table , options , cb ) ;
122+ let schema = args . schema ;
123123
124124 table = args . table ;
125125 options = args . options ;
@@ -131,8 +131,8 @@ function mixinDiscovery(PostgreSQL) {
131131 self . setDefaultOptions ( options ) ;
132132 cb = args . cb ;
133133
134- var sql = self . buildQueryColumns ( schema , table ) ;
135- var callback = function ( err , results ) {
134+ const sql = self . buildQueryColumns ( schema , table ) ;
135+ const callback = function ( err , results ) {
136136 if ( err ) {
137137 cb ( err , results ) ;
138138 } else {
@@ -164,23 +164,23 @@ function mixinDiscovery(PostgreSQL) {
164164 * @returns {String } The sql statement
165165 */
166166 PostgreSQL . prototype . buildQueryColumns = function ( owner , table ) {
167- var sql = null ;
167+ let sql = null ;
168168 if ( owner ) {
169169 sql = this . paginateSQL ( 'SELECT table_schema AS "owner", table_name AS "tableName", column_name AS "columnName",'
170170 + 'data_type AS "dataType", character_maximum_length AS "dataLength", numeric_precision AS "dataPrecision",'
171171 + ' numeric_scale AS "dataScale", is_nullable AS "nullable"'
172172 + ' FROM information_schema.columns'
173173 + ' WHERE table_schema=\'' + owner + '\''
174174 + ( table ? ' AND table_name=\'' + table + '\'' : '' ) ,
175- 'table_name, ordinal_position' , { } ) ;
175+ 'table_name, ordinal_position' , { } ) ;
176176 } else {
177177 sql = this . paginateSQL ( 'SELECT current_schema() AS "owner", table_name AS "tableName",'
178178 + ' column_name AS "columnName",'
179179 + ' data_type AS "dataType", character_maximum_length AS "dataLength", numeric_precision AS "dataPrecision",'
180180 + ' numeric_scale AS "dataScale", is_nullable AS "nullable"'
181181 + ' FROM information_schema.columns'
182182 + ( table ? ' WHERE table_name=\'' + table + '\'' : '' ) ,
183- 'table_name, ordinal_position' , { } ) ;
183+ 'table_name, ordinal_position' , { } ) ;
184184 }
185185 return sql ;
186186 } ;
@@ -193,7 +193,7 @@ function mixinDiscovery(PostgreSQL) {
193193 *
194194 */
195195
196- // http://docs.oracle.com/javase/6/docs/api/java/sql/DatabaseMetaData.html#getPrimaryKeys(java.lang.String, java.lang.String, java.lang.String)
196+ // http://docs.oracle.com/javase/6/docs/api/java/sql/DatabaseMetaData.html#getPrimaryKeys(java.lang.String, java.lang.String, java.lang.String)
197197
198198 /*
199199 SELECT kc.table_schema AS "owner", kc.table_name AS "tableName",
@@ -212,7 +212,7 @@ function mixinDiscovery(PostgreSQL) {
212212 * @returns {string }
213213 */
214214 PostgreSQL . prototype . buildQueryPrimaryKeys = function ( owner , table ) {
215- var sql = 'SELECT kc.table_schema AS "owner", '
215+ let sql = 'SELECT kc.table_schema AS "owner", '
216216 + 'kc.table_name AS "tableName", kc.column_name AS "columnName",'
217217 + ' kc.ordinal_position AS "keySeq",'
218218 + ' kc.constraint_name AS "pkName" FROM'
@@ -260,7 +260,7 @@ function mixinDiscovery(PostgreSQL) {
260260 * @returns {string }
261261 */
262262 PostgreSQL . prototype . buildQueryForeignKeys = function ( owner , table ) {
263- var sql =
263+ let sql =
264264 'SELECT tc.table_schema AS "fkOwner", tc.constraint_name AS "fkName", tc.table_name AS "fkTableName",'
265265 + ' kcu.column_name AS "fkColumnName", kcu.ordinal_position AS "keySeq",'
266266 + ' ccu.table_schema AS "pkOwner",'
@@ -298,7 +298,7 @@ function mixinDiscovery(PostgreSQL) {
298298 * @returns {string }
299299 */
300300 PostgreSQL . prototype . buildQueryExportedForeignKeys = function ( owner , table ) {
301- var sql = 'SELECT kcu.constraint_name AS "fkName", kcu.table_schema AS "fkOwner", kcu.table_name AS "fkTableName",'
301+ let sql = 'SELECT kcu.constraint_name AS "fkName", kcu.table_schema AS "fkOwner", kcu.table_name AS "fkTableName",'
302302 + ' kcu.column_name AS "fkColumnName", kcu.ordinal_position AS "keySeq",'
303303 + ' (SELECT constraint_name'
304304 + ' FROM information_schema.table_constraints tc2'
@@ -328,8 +328,8 @@ function mixinDiscovery(PostgreSQL) {
328328 */
329329
330330 PostgreSQL . prototype . buildPropertyType = function ( columnDefinition , dataLength ) {
331- var mysqlType = columnDefinition . dataType ;
332- var type = mysqlType . toUpperCase ( ) ;
331+ const mysqlType = columnDefinition . dataType ;
332+ const type = mysqlType . toUpperCase ( ) ;
333333 switch ( type ) {
334334 case 'BOOLEAN' :
335335 return 'Boolean' ;
@@ -369,7 +369,7 @@ function mixinDiscovery(PostgreSQL) {
369369 */
370370 PostgreSQL . prototype . discoverModelIndexes = function ( model , cb ) {
371371 this . getTableStatus ( model , function ( err , fields , indexes ) {
372- var indexData = { } ;
372+ const indexData = { } ;
373373 indexes . forEach ( function ( index ) {
374374 indexData [ index . name ] = index ;
375375 delete index . name ;
0 commit comments