@@ -158,89 +158,89 @@ function mixinDiscovery(MySQL, mysql) {
158
158
let sql = null ;
159
159
if ( schema ) {
160
160
sql = paginateSQL (
161
- `SELECT
162
- c .table_schema AS "owner",
163
- c .table_name AS "tableName",
164
- c .column_name AS "columnName",
165
- c .data_type AS "dataType",
166
- c .character_maximum_length AS "dataLength",
167
- c .numeric_precision AS "dataPrecision",
168
- c .numeric_scale AS "dataScale",
169
- c .column_type AS "columnType",
170
- c .is_nullable = 'YES' AS "nullable",
171
- CASE WHEN c .extra LIKE '%auto_increment%' THEN 1 ELSE 0 END AS "generated",
172
- s .index_name AS "indexName",
173
- s .non_unique AS "nonUnique",
174
- s .seq_in_index AS "seqInIndex",
175
- s .cardinality AS "cardinality",
176
- s .index_type AS "indexType",
177
- CASE WHEN fk.column_name IS NOT NULL THEN 1 ELSE 0 END AS "isForeignKey" -- Flag for foreign key
178
- FROM
179
- information_schema.columns c
180
- LEFT JOIN
181
- information_schema.statistics s
182
- ON
183
- c .table_schema = s .table_schema
184
- AND c .table_name = s .table_name
185
- AND c .column_name = s .column_name
186
- LEFT JOIN
187
- information_schema.KEY_COLUMN_USAGE fk
188
- ON
189
- c .table_schema = fk.table_schema
190
- AND c .table_name = fk.table_name
191
- AND c .column_name = fk.column_name
192
- AND fk.referenced_table_name IS NOT NULL -- Ensure it's a foreign key
193
- WHERE
194
- c .table_schema = ${ mysql . escape ( schema ) }
195
- ${ table ? ' AND c .table_name = ' + mysql . escape ( table ) : '' }
161
+ `SELECT
162
+ cols .table_schema AS "owner",
163
+ cols .table_name AS "tableName",
164
+ cols .column_name AS "columnName",
165
+ cols .data_type AS "dataType",
166
+ cols .character_maximum_length AS "dataLength",
167
+ cols .numeric_precision AS "dataPrecision",
168
+ cols .numeric_scale AS "dataScale",
169
+ cols .column_type AS "columnType",
170
+ cols .is_nullable = 'YES' AS "nullable",
171
+ CASE WHEN cols .extra LIKE '%auto_increment%' THEN 1 ELSE 0 END AS "generated",
172
+ indexes .index_name AS "indexName",
173
+ indexes .non_unique AS "nonUnique",
174
+ indexes .seq_in_index AS "seqInIndex",
175
+ indexes .cardinality AS "cardinality",
176
+ indexes .index_type AS "indexType",
177
+ CASE WHEN fk.column_name IS NOT NULL THEN 1 ELSE 0 END AS "isForeignKey"
178
+ FROM
179
+ information_schema.columns cols
180
+ LEFT JOIN
181
+ information_schema.statistics indexes
182
+ ON
183
+ cols .table_schema = indexes .table_schema
184
+ AND cols .table_name = indexes .table_name
185
+ AND cols .column_name = indexes .column_name
186
+ LEFT JOIN
187
+ information_schema.KEY_COLUMN_USAGE fk
188
+ ON
189
+ cols .table_schema = fk.table_schema
190
+ AND cols .table_name = fk.table_name
191
+ AND cols .column_name = fk.column_name
192
+ AND fk.referenced_table_name IS NOT NULL
193
+ WHERE
194
+ cols .table_schema = ${ mysql . escape ( schema ) }
195
+ ${ table ? ' AND cols .table_name = ' + mysql . escape ( table ) : '' }
196
196
` ,
197
- 'c .table_name, c .ordinal_position' ,
197
+ 'cols .table_name, cols .ordinal_position' ,
198
198
{ } ,
199
199
) ;
200
200
} else {
201
201
sql = paginateSQL (
202
- `SELECT
203
- columns .table_schema AS "owner",
204
- columns .table_name AS "tableName",
205
- columns .column_name AS "columnName",
206
- columns .data_type AS "dataType",
207
- columns .character_maximum_length AS "dataLength",
208
- columns .numeric_precision AS "dataPrecision",
209
- columns .numeric_scale AS "dataScale",
210
- columns .column_type AS "columnType",
211
- columns .is_nullable = 'YES' AS "nullable",
212
- CASE WHEN columns .extra LIKE '%auto_increment%' THEN 1 ELSE 0 END AS "generated",
202
+ `SELECT
203
+ cols .table_schema AS "owner",
204
+ cols .table_name AS "tableName",
205
+ cols .column_name AS "columnName",
206
+ cols .data_type AS "dataType",
207
+ cols .character_maximum_length AS "dataLength",
208
+ cols .numeric_precision AS "dataPrecision",
209
+ cols .numeric_scale AS "dataScale",
210
+ cols .column_type AS "columnType",
211
+ cols .is_nullable = 'YES' AS "nullable",
212
+ CASE WHEN cols .extra LIKE '%auto_increment%' THEN 1 ELSE 0 END AS "generated",
213
213
indexes.index_name AS "indexName",
214
214
indexes.seq_in_index AS "indexColumnOrder",
215
215
indexes.non_unique AS "nonUnique",
216
- indexes.cardinality AS "cardinality", -- Cardinality of the index
217
- indexes.index_type AS "indexType", -- Type of the index
218
- CASE WHEN fk.column_name IS NOT NULL THEN 1 ELSE 0 END AS "isForeignKey" -- Flag for foreign key
219
- FROM
220
- information_schema.columns AS columns
221
- LEFT JOIN
222
- information_schema.statistics AS indexes
223
- ON
224
- columns .table_schema = indexes.table_schema
225
- AND columns .table_name = indexes.table_name
226
- AND columns .column_name = indexes.column_name
227
- LEFT JOIN
228
- information_schema.KEY_COLUMN_USAGE AS fk
229
- ON
230
- columns .table_schema = fk.table_schema
231
- AND columns .table_name = fk.table_name
232
- AND columns .column_name = fk.column_name
233
- AND fk.referenced_table_name IS NOT NULL -- Ensure it's a foreign key
234
- WHERE
235
- columns .table_schema = ${ mysql . escape ( schema ) }
236
- ${ table ? ' AND columns .table_name = ' + mysql . escape ( table ) : '' }
216
+ indexes.cardinality AS "cardinality",
217
+ indexes.index_type AS "indexType",
218
+ CASE WHEN fk.column_name IS NOT NULL THEN 1 ELSE 0 END AS "isForeignKey"
219
+ FROM
220
+ information_schema.columns AS cols
221
+ LEFT JOIN
222
+ information_schema.statistics AS indexes
223
+ ON
224
+ cols .table_schema = indexes.table_schema
225
+ AND cols .table_name = indexes.table_name
226
+ AND cols .column_name = indexes.column_name
227
+ LEFT JOIN
228
+ information_schema.KEY_COLUMN_USAGE AS fk
229
+ ON
230
+ cols .table_schema = fk.table_schema
231
+ AND cols .table_name = fk.table_name
232
+ AND cols .column_name = fk.column_name
233
+ AND fk.referenced_table_name IS NOT NULL
234
+ WHERE
235
+ cols .table_schema = ${ mysql . escape ( schema ) }
236
+ ${ table ? ' AND cols .table_name = ' + mysql . escape ( table ) : '' }
237
237
` ,
238
- 'columns .table_name, columns .ordinal_position' ,
238
+ 'cols .table_name, cols .ordinal_position' ,
239
239
{ } ,
240
240
) ;
241
241
}
242
242
if ( options . orderBy ) {
243
- sql += ' ORDER BY ' + options . orderBy ;
243
+ sql += ' ORDER BY ' + 'cols.' + options . orderBy ;
244
244
}
245
245
return sql ;
246
246
} ;
0 commit comments