ModelQuery: allow specifying raw value for sortBy()
This commit is contained in:
parent
23d54c4f03
commit
3a4606b328
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "wms-core",
|
||||
"version": "0.22.0-rc.1",
|
||||
"version": "0.22.0-rc.2",
|
||||
"description": "Node web application framework and toolbelt.",
|
||||
"repository": "https://gitlab.com/ArisuOngaku/wms-core",
|
||||
"author": "Alice Gaudon <alice@gaudon.pro>",
|
||||
|
@ -94,8 +94,8 @@ export default class ModelQuery<M extends Model> implements WhereFieldConsumer<M
|
||||
return this;
|
||||
}
|
||||
|
||||
public sortBy(field: string, direction: 'ASC' | 'DESC' = 'ASC'): this {
|
||||
this._sortBy = field.split('.').map(v => v.startsWith('`') ? v : `\`${v}\``).join('.');
|
||||
public sortBy(field: string, direction: 'ASC' | 'DESC' = 'ASC', raw: boolean = false): this {
|
||||
this._sortBy = raw ? field : field.split('.').map(v => v.startsWith('`') ? v : `\`${v}\``).join('.');
|
||||
this._sortDirection = direction;
|
||||
return this;
|
||||
}
|
||||
|
@ -7,6 +7,10 @@ describe('Test ModelQuery', () => {
|
||||
const query = ModelQuery.select({table: 'model'} as unknown as ModelFactory<Model>)
|
||||
.sortBy('model.f2', 'ASC');
|
||||
expect(query.toString(true)).toBe('SELECT `model`.* FROM `model` ORDER BY `model`.`f2` ASC');
|
||||
|
||||
const queryRaw = ModelQuery.select({table: 'model'} as unknown as ModelFactory<Model>)
|
||||
.sortBy('coalesce(model.f1, model.f2)', 'ASC', true);
|
||||
expect(queryRaw.toString(true)).toBe('SELECT `model`.* FROM `model` ORDER BY coalesce(model.f1, model.f2) ASC');
|
||||
});
|
||||
|
||||
test('update', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user