(entityName: EntityName<T>, where: any, options: CountOptions<T> = {})
| 878 | } |
| 879 | |
| 880 | async count<T extends object>(entityName: EntityName<T>, where: any, options: CountOptions<T> = {}): Promise<number> { |
| 881 | const meta = this.metadata.get(entityName); |
| 882 | |
| 883 | if (meta.virtual) { |
| 884 | return this.countVirtual<T>(entityName, where, options); |
| 885 | } |
| 886 | |
| 887 | if (options.unionWhere?.length) { |
| 888 | where = await this.applyUnionWhere(meta, where, options); |
| 889 | } |
| 890 | |
| 891 | options = { populate: [], ...options }; |
| 892 | const populate = options.populate as unknown as PopulateOptions<T>[]; |
| 893 | const joinedProps = this.joinedProps(meta, populate, options as FindOptions<T>); |
| 894 | const schema = this.getSchemaName(meta, options); |
| 895 | const qb = this.createQueryBuilder<T>(entityName, options.ctx, options.connectionType, false, options.logging); |
| 896 | qb.setAbortOptions(pickAbortOptions(options)); |
| 897 | const populateWhere = this.buildPopulateWhere(meta, joinedProps, options); |
| 898 | |
| 899 | if (meta && !Utils.isEmpty(populate)) { |
| 900 | this.buildFields(meta, populate, joinedProps, qb, qb.alias, options as FindOptions<T>, schema); |
| 901 | } |
| 902 | |
| 903 | this.validateSqlOptions(options); |
| 904 | |
| 905 | qb.state.resolvedPopulateWhere = (options as Dictionary)._populateWhere; |
| 906 | qb.indexHint(options.indexHint as string) |
| 907 | .collation(options.collation as string) |
| 908 | .comment(options.comments) |
| 909 | .hintComment(options.hintComments) |
| 910 | .groupBy(options.groupBy as any) |
| 911 | .having(options.having as any) |
| 912 | .populate( |
| 913 | populate, |
| 914 | joinedProps.length > 0 ? populateWhere : undefined, |
| 915 | joinedProps.length > 0 ? options.populateFilter : undefined, |
| 916 | ) |
| 917 | .withSchema(schema) |
| 918 | .where(where); |
| 919 | |
| 920 | if (options.em) { |
| 921 | await qb.applyJoinedFilters(options.em, options.filters); |
| 922 | } |
| 923 | |
| 924 | return this.rethrow(qb.getCount()); |
| 925 | } |
| 926 | |
| 927 | async nativeInsert<T extends object>( |
| 928 | entityName: EntityName<T>, |
nothing calls this directly
no test coverage detected