Skip to content

Commit 89165ef

Browse files
committed
feat: query to fetch unique columns
Signed-off-by: Muhammad Aaqil <[email protected]>
1 parent 858adf3 commit 89165ef

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

lib/discovery.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,29 @@ function mixinDiscovery(MySQL, mysql) {
298298
return sql;
299299
};
300300

301+
/**
302+
* Discover unique keys for a given table
303+
* @param {String} table The table name
304+
* @param {Object} options The options for discovery
305+
*/
306+
307+
/*!
308+
* Retrieves a list of column names that have unique key index
309+
* @param schema
310+
* @param table
311+
* @returns {string}
312+
*/
313+
MySQL.prototype.buildQueryUniqueKeys = function(schema, table) {
314+
const sql = 'SELECT Column_name AS "columnName",' +
315+
' table_schema AS "owner",' +
316+
' table_name AS "tableName"' +
317+
' FROM Information_schema.statistics' +
318+
' WHERE Table_schema = ' + mysql.escape(schema) +
319+
' AND Table_name = ' + mysql.escape(table) +
320+
' AND Non_unique = 0 AND Index_name <> \'PRIMARY\';';
321+
return sql;
322+
}
323+
301324
/**
302325
* Discover foreign keys that reference to the primary key of this table
303326
* @param {String} table The table name

0 commit comments

Comments
 (0)