n00ki
n00ki
DTDrizzle Team
Created by n00ki on 7/30/2024 in #help
How to use findMany() with distinct column values?
Hi Everyone 🙂 I’m using the findMany() query in my project to retrieve the latest records from an SQLite (libsql) database:
export const getLatestRecords = db.query.Record.findMany({
with: {
owner: true
},
limit: sql.placeholder('limit'),
orderBy: (records, { desc }) => [desc(records.createdAt)]
});
export const getLatestRecords = db.query.Record.findMany({
with: {
owner: true
},
limit: sql.placeholder('limit'),
orderBy: (records, { desc }) => [desc(records.createdAt)]
});
I want to modify it to exclude any records with duplicate ownerId column values. If more than one record exists for a specific ownderId, I would like to get one (the latest) and exclude all others. Does something like distinctOn already exist in Drizzle? I would highly appreciate any assistance. Thanks a lot🙏
5 replies
DTDrizzle Team
Created by n00ki on 5/26/2024 in #help
Properly inferring Prepared Statement Return Type when executing a query
No description
3 replies