fix: add order by ordinal position for query columns
Signed-off-by: Muhammad Aaqil <aaqilcs102@gmail.com>
This commit is contained in:
parent
858adf3a66
commit
8b94368ed4
|
@ -154,7 +154,7 @@ function mixinDiscovery(MySQL, mysql) {
|
||||||
* @param table
|
* @param table
|
||||||
* @returns {String} The sql statement
|
* @returns {String} The sql statement
|
||||||
*/
|
*/
|
||||||
MySQL.prototype.buildQueryColumns = function(schema, table) {
|
MySQL.prototype.buildQueryColumns = function(schema, table, options = {}) {
|
||||||
let sql = null;
|
let sql = null;
|
||||||
if (schema) {
|
if (schema) {
|
||||||
sql = paginateSQL('SELECT table_schema AS "owner",' +
|
sql = paginateSQL('SELECT table_schema AS "owner",' +
|
||||||
|
@ -186,6 +186,9 @@ function mixinDiscovery(MySQL, mysql) {
|
||||||
(table ? ' WHERE table_name=' + mysql.escape(table) : ''),
|
(table ? ' WHERE table_name=' + mysql.escape(table) : ''),
|
||||||
'table_name, ordinal_position', {});
|
'table_name, ordinal_position', {});
|
||||||
}
|
}
|
||||||
|
if (options.orderBy) {
|
||||||
|
sql += ' ORDER BY ' + options.orderBy;
|
||||||
|
}
|
||||||
return sql;
|
return sql;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -126,6 +126,32 @@ describe('Discover models including other users', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Discover model properties', function() {
|
describe('Discover model properties', function() {
|
||||||
|
describe('Discover model properties in Ordinal Order', function() {
|
||||||
|
it('should return an array of columns for product in ordinal order', function(done) {
|
||||||
|
const productProperties = [];
|
||||||
|
const productPropertiesInOrdinalOrder = [
|
||||||
|
'ID',
|
||||||
|
'NAME',
|
||||||
|
'AUDIBLE_RANGE',
|
||||||
|
'EFFECTIVE_RANGE',
|
||||||
|
'ROUNDS',
|
||||||
|
'EXTRAS',
|
||||||
|
'FIRE_MODES',
|
||||||
|
];
|
||||||
|
db.discoverModelProperties('PRODUCT', {orderBy: 'ordinal_position'}, function(err, models) {
|
||||||
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
|
done(err);
|
||||||
|
} else {
|
||||||
|
models.forEach(function(m) { productProperties.push(m.columnName); });
|
||||||
|
productProperties.forEach((prop, index) => {
|
||||||
|
assert(productPropertiesInOrdinalOrder[index] === prop);
|
||||||
|
});
|
||||||
|
done(null, models);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
describe('Discover a named model', function() {
|
describe('Discover a named model', function() {
|
||||||
it('should return an array of columns for product', function(done) {
|
it('should return an array of columns for product', function(done) {
|
||||||
db.discoverModelProperties('product', function(err, models) {
|
db.discoverModelProperties('product', function(err, models) {
|
||||||
|
|
Loading…
Reference in New Issue