我想在node orm中使用find方法获取已排序的项目。我知道有和'命令'在find()中的参数,它会给我排序的项目来自' a-z'。如果我想从' z-a'中获取商品,我该怎么办?这意味着' GROUP BY DESC'可以在node-orm中使用吗?
答案 0 :(得分:0)
There is a method for group by
UserModel.find({id: id_value}).groupBy({column1, column2}).order('-name').
In the ORM library you can find the below function which will guide you more.
export interface SelectQuery {
select(fields: string): SelectQuery;
calculateFoundRows: SelectQuery;
as(alias: string): SelectQuery;
fun(fun: string, column: string, alias: string): SelectQuery;
from(table: string, from_id: string, to_id: string): SelectQuery;
from(table: string, from_id: string, to_table: string, to_id: string): SelectQuery;
where(...args: any[]): SelectQuery;
whereExists(table: string, table_link: string, link: string, conditions: { [column: string]: any }): SelectQuery;
groupBy(...columns: string[]): SelectQuery;
offset(offset: number): SelectQuery;
limit(limit: number): SelectQuery;
order(column: string, direction: string): SelectQuery;
build(): string;
}