Building a simple blog app; how do I order posts from the database in order of latest posts 1st or at the top?


#1

Building a simple blog app; how do I order posts from the database in order of latest posts 1st or at the top?


#2

maybe

const data = await ModelName.query().orderBy('PK', 'desc').fetch()

If you have a PK then order data through it

The orderBy() method accepts two arguments

1.- columnName that you will use to order your data
2.- desc the order desired to accommodate all your records

Or if you’re not using any Model then write your query in this way

const data = await Database.table('tableName').select('*').orderBy('PK', 'desc')


#3

that works. Thanks