mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 23:28:02 +00:00
Add Grab A Limited Set Of Records as a Prisma TIL
This commit is contained in:
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
|||||||
|
|
||||||
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
||||||
|
|
||||||
_1203 TILs and counting..._
|
_1204 TILs and counting..._
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -44,6 +44,7 @@ _1203 TILs and counting..._
|
|||||||
* [Next.js](#nextjs)
|
* [Next.js](#nextjs)
|
||||||
* [Phoenix](#phoenix)
|
* [Phoenix](#phoenix)
|
||||||
* [PostgreSQL](#postgresql)
|
* [PostgreSQL](#postgresql)
|
||||||
|
* [Prisma](#prisma)
|
||||||
* [Python](#python)
|
* [Python](#python)
|
||||||
* [Rails](#rails)
|
* [Rails](#rails)
|
||||||
* [React](#react)
|
* [React](#react)
|
||||||
@@ -678,6 +679,10 @@ _1203 TILs and counting..._
|
|||||||
- [Word Count for a Column](postgres/word-count-for-a-column.md)
|
- [Word Count for a Column](postgres/word-count-for-a-column.md)
|
||||||
- [Write A Query Result To File](postgres/write-a-query-result-to-file.md)
|
- [Write A Query Result To File](postgres/write-a-query-result-to-file.md)
|
||||||
|
|
||||||
|
### Prisma
|
||||||
|
|
||||||
|
- [Grab A Limited Set Of Records](prisma/grab-a-limited-set-of-records.md)
|
||||||
|
|
||||||
### Python
|
### Python
|
||||||
|
|
||||||
- [Access Instance Variables](python/access-instance-variables.md)
|
- [Access Instance Variables](python/access-instance-variables.md)
|
||||||
|
|||||||
27
prisma/grab-a-limited-set-of-records.md
Normal file
27
prisma/grab-a-limited-set-of-records.md
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
# Grab A Limited Set Of Records
|
||||||
|
|
||||||
|
Let's say you want to grab some records from a table, but you want to limit the
|
||||||
|
result set to 10 records.
|
||||||
|
|
||||||
|
You can do that with the `take` option.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const posts = await prisma.post.findMany({
|
||||||
|
take: 10
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
It is generally good to not assume anything about the ordering. Instead, you
|
||||||
|
should be explicit about the order you want, so let's include an `orderBy` as
|
||||||
|
well.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const posts = await prisma.post.findMany({
|
||||||
|
take: 10,
|
||||||
|
orderBy: { createdAt: "asc" },
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
This will return the 10 most recently created posts.
|
||||||
|
|
||||||
|
[source](https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#findmany)
|
||||||
Reference in New Issue
Block a user