不要怂,就是干,撸起袖子干!

Commit 638b13b2 by Mirko Jotic Committed by Sushant

feat(typings): model.count with group by (#10763)

1 parent 7a6c60d7
Showing with 25 additions and 0 deletions
...@@ -527,6 +527,18 @@ export interface CountOptions extends Logging, Transactionable, Filterable, Proj ...@@ -527,6 +527,18 @@ export interface CountOptions extends Logging, Transactionable, Filterable, Proj
col?: string; col?: string;
} }
/**
* Options for Model.count when GROUP BY is used
*/
export interface CountWithOptions extends CountOptions {
/**
* GROUP BY in sql
* Used in conjunction with `attributes`.
* @see Projectable
*/
group: GroupOption;
}
export interface FindAndCountOptions extends CountOptions, FindOptions {} export interface FindAndCountOptions extends CountOptions, FindOptions {}
/** /**
...@@ -1744,6 +1756,11 @@ export abstract class Model<T = any, T2 = any> extends Hooks { ...@@ -1744,6 +1756,11 @@ export abstract class Model<T = any, T2 = any> extends Hooks {
): Promise<T>; ): Promise<T>;
/** /**
* Count number of records if group by is used
*/
public static count(options: CountWithOptions): Promise<{ [key: string]: number }>;
/**
* Count the number of records matching the provided where clause. * Count the number of records matching the provided where clause.
* *
* If you provide an `include` option, the number of matching associations will be counted instead. * If you provide an `include` option, the number of matching associations will be counted instead.
......
import { Model, Promise } from 'sequelize';
class MyModel extends Model {}
const grouped: Promise<{ [key: string]: number }> = MyModel.count({ group: 'tag' });
const counted: Promise<number> = MyModel.count();
const countedDistinct: Promise<number> = MyModel.count({ col: 'tag', distinct: true });
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!