Skip to content

Commit

Permalink
add order by ordinal position for query columns
Browse files Browse the repository at this point in the history
Signed-off-by: Muhammad Aaqil <[email protected]>
  • Loading branch information
aaqilniz committed Oct 15, 2023
1 parent 21e3bba commit 8b8ab91
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ function mixinDiscovery(MySQL, mysql) {
(table ? ' WHERE table_name=' + mysql.escape(table) : ''),
'table_name, ordinal_position', {});
}
sql += ' ORDER BY ordinal_position';
return sql;
};

Expand Down
28 changes: 28 additions & 0 deletions test/mysql.discover.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,34 @@ describe('Discover models including other users', 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', function(err, models) {
if (err) {
console.error(err);
done(err);
} else {
models.forEach(function(m) {
productProperties.push(m.columnName)
});

Check failure on line 147 in test/mysql.discover.test.js

View workflow job for this annotation

GitHub Actions / Code Lint

Missing semicolon
productProperties.forEach((prop, index) => {
assert(productPropertiesInOrdinalOrder[index] === prop);
});
done(null, models);
}
});
});
});
describe('Discover a named model', function() {
it('should return an array of columns for product', function(done) {
db.discoverModelProperties('product', function(err, models) {
Expand Down

0 comments on commit 8b8ab91

Please sign in to comment.