diff --git a/lib/discovery.js b/lib/discovery.js index 666d12174..d1cc4f1f9 100644 --- a/lib/discovery.js +++ b/lib/discovery.js @@ -154,7 +154,7 @@ function mixinDiscovery(MySQL, mysql) { * @param table * @returns {String} The sql statement */ - MySQL.prototype.buildQueryColumns = function(schema, table) { + MySQL.prototype.buildQueryColumns = function(schema, table, options) { let sql = null; if (schema) { sql = paginateSQL('SELECT table_schema AS "owner",' + @@ -186,7 +186,9 @@ function mixinDiscovery(MySQL, mysql) { (table ? ' WHERE table_name=' + mysql.escape(table) : ''), 'table_name, ordinal_position', {}); } - sql += ' ORDER BY ordinal_position'; + if (options.orderBy) { + sql += ' ORDER BY ' + options.orderBy; + } return sql; };