n00ki
n00ki
DTDrizzle Team
Created by GStudiosX2 on 7/31/2024 in #help
Get N of last rows
@GStudiosX2 what I often do is using a serial id with autoincrement and a text public_id column where it’s needed
28 replies
DTDrizzle Team
Created by GStudiosX2 on 7/31/2024 in #help
Get N of last rows
you can order by multiple fields... something like db.select().from(table).orderBy(desc(table.id), asc(table.created_at));
28 replies
DTDrizzle Team
Created by GStudiosX2 on 7/31/2024 in #help
Get N of last rows
Ok, so use asc instead of desc? Yet, these are not the latest records
28 replies
DTDrizzle Team
Created by GStudiosX2 on 7/31/2024 in #help
Get N of last rows
You can also use a prepared statement with placeholder if you want to reuse it for different limits (N)
28 replies
DTDrizzle Team
Created by GStudiosX2 on 7/31/2024 in #help
Get N of last rows
Hi @GStudiosX2 👋 You can use a combination of orderBy (on id or createdAt, if exists in your table) and limit.
const result = await db
.select()
.from(yourTable)
.orderBy(desc(yourTable.id)) // Assuming 'id' is your primary key or timestamp field
.limit(n);
const result = await db
.select()
.from(yourTable)
.orderBy(desc(yourTable.id)) // Assuming 'id' is your primary key or timestamp field
.limit(n);
28 replies
DTDrizzle Team
Created by n00ki on 7/30/2024 in #help
How to use findMany() with distinct column values?
Thanks @Raphaël M (@rphlmr) ⚡! If that's the case, maybe you can try to help me think of a way to achieve the desired query? if I understand correctly, the absence of distinctOn means I can't use the findMany API for this specific case, right?
5 replies
DTDrizzle Team
Created by n00ki on 5/26/2024 in #help
Properly inferring Prepared Statement Return Type when executing a query
anyone?🙊
3 replies