Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: query to fetch unique columns #580

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we write a test case for this ?

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
* @param {String} table The table name
Expand Down