docs: documented getCount() method (#9847)

* documented getCount()

getCount() is currently only mentioned in the documentation once, and you're never shown how to use it. This patch adds a little documentation for getCount()

* clarification
This commit is contained in:
JT Smith 2023-04-05 05:42:30 -05:00 committed by GitHub
parent 58fc08840a
commit f7b210bedb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,6 +4,7 @@
- [Important note when using the `QueryBuilder`](#important-note-when-using-the-querybuilder)
- [How to create and use a `QueryBuilder`](#how-to-create-and-use-a-querybuilder)
- [Getting values using QueryBuilder](#getting-values-using-querybuilder)
- [Getting a count](#getting-a-count)
- [What are aliases for?](#what-are-aliases-for)
- [Using parameters to escape data](#using-parameters-to-escape-data)
- [Adding `WHERE` expression](#adding-where-expression)
@ -252,6 +253,24 @@ const photosSums = await dataSource
// result will be like this: [{ id: 1, sum: 25 }, { id: 2, sum: 13 }, ...]
```
## Getting a count
You can get the count on the number of rows a query will return by using `getCount()`. This will return the count as a number rather than an Entity result.
```typescript
const count = await dataSource
.getRepository(User)
.createQueryBuilder("user")
.where("user.name = :name", { name: "Timber" })
.getCount()
```
Which produces the following SQL query:
```sql
SELECT count(*) FROM users user WHERE user.name = 'Timber'
```
## What are aliases for?
We used `createQueryBuilder("user")`. But what is "user"?