Skip to content

Commit

Permalink
feat: query to fetch unique columns
Browse files Browse the repository at this point in the history
Signed-off-by: Muhammad Aaqil <[email protected]>
  • Loading branch information
aaqilniz committed Apr 14, 2024
1 parent 858adf3 commit 89165ef
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,29 @@ function mixinDiscovery(MySQL, mysql) {
return sql;
};

/**
* Discover unique keys for a given table
* @param {String} table The table name
* @param {Object} options The options for discovery
*/

/*!
* Retrieves a list of column names that have unique key index
* @param schema
* @param table
* @returns {string}
*/
MySQL.prototype.buildQueryUniqueKeys = function(schema, table) {
const sql = 'SELECT Column_name AS "columnName",' +
' table_schema AS "owner",' +
' table_name AS "tableName"' +
' FROM Information_schema.statistics' +
' WHERE Table_schema = ' + mysql.escape(schema) +
' AND Table_name = ' + mysql.escape(table) +
' AND Non_unique = 0 AND Index_name <> \'PRIMARY\';';
return sql;
}

/**
* Discover foreign keys that reference to the primary key of this table

Check failure on line 325 in lib/discovery.js

View workflow job for this annotation

GitHub Actions / Code Lint

Trailing spaces not allowed

Check failure on line 325 in lib/discovery.js

View workflow job for this annotation

GitHub Actions / Code Lint

Missing semicolon

Check failure on line 325 in lib/discovery.js

View workflow job for this annotation

GitHub Actions / build (18)

Trailing spaces not allowed

Check failure on line 325 in lib/discovery.js

View workflow job for this annotation

GitHub Actions / build (18)

Missing semicolon

Check failure on line 325 in lib/discovery.js

View workflow job for this annotation

GitHub Actions / build (20)

Trailing spaces not allowed

Check failure on line 325 in lib/discovery.js

View workflow job for this annotation

GitHub Actions / build (20)

Missing semicolon
* @param {String} table The table name
Expand Down

0 comments on commit 89165ef

Please sign in to comment.