Prisma, how to reverse order

I was getting data from the database using Prisma.

In my specific case I was getting tweets from the Tweets table, and they were listed from oldest to newest.

I wanted the opposite, like Twitter works – the newest shows up first.

So I picked my data fetching procedure:

await prisma.tweet.findMany({})

and I added an orderBy attribute to order by id in descending order:

await prisma.tweet.findMany({
  orderBy: [
    {
      id: 'desc'
    }
  ]
})

I was getting data from the database using Prisma.

In my specific case I was getting tweets from the Tweets table, and they were listed from oldest to newest.

I wanted the opposite, like Twitter works – the newest shows up first.

So I picked my data fetching procedure:

await prisma.tweet.findMany({})

and I added an orderBy attribute to order by id in descending order:

await prisma.tweet.findMany({
  orderBy: [
    {
      id: 'desc'
    }
  ]
})

Print Share Comment Cite Upload Translate
APA
flaviocopes.com | Sciencx (2024-03-29T08:30:25+00:00) » Prisma, how to reverse order. Retrieved from https://www.scien.cx/2021/07/15/prisma-how-to-reverse-order/.
MLA
" » Prisma, how to reverse order." flaviocopes.com | Sciencx - Thursday July 15, 2021, https://www.scien.cx/2021/07/15/prisma-how-to-reverse-order/
HARVARD
flaviocopes.com | Sciencx Thursday July 15, 2021 » Prisma, how to reverse order., viewed 2024-03-29T08:30:25+00:00,<https://www.scien.cx/2021/07/15/prisma-how-to-reverse-order/>
VANCOUVER
flaviocopes.com | Sciencx - » Prisma, how to reverse order. [Internet]. [Accessed 2024-03-29T08:30:25+00:00]. Available from: https://www.scien.cx/2021/07/15/prisma-how-to-reverse-order/
CHICAGO
" » Prisma, how to reverse order." flaviocopes.com | Sciencx - Accessed 2024-03-29T08:30:25+00:00. https://www.scien.cx/2021/07/15/prisma-how-to-reverse-order/
IEEE
" » Prisma, how to reverse order." flaviocopes.com | Sciencx [Online]. Available: https://www.scien.cx/2021/07/15/prisma-how-to-reverse-order/. [Accessed: 2024-03-29T08:30:25+00:00]
rf:citation
» Prisma, how to reverse order | flaviocopes.com | Sciencx | https://www.scien.cx/2021/07/15/prisma-how-to-reverse-order/ | 2024-03-29T08:30:25+00:00
https://github.com/addpipe/simple-recorderjs-demo