mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
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:
parent
58fc08840a
commit
f7b210bedb
@ -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"?
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user