Augustin Sorel
Augustin Sorel
Explore posts from servers
DTDrizzle Team
Created by Augustin Sorel on 5/22/2024 in #help
Order by in a query clause
Hey guys, I am trying to retrieve a list of exercises and it's data + grid position (join) from my database. I also want this array of result to be ordered by it's grid position. Here is what I came up with (the following code works just fine however notice the javascript .sort rather than using the drizzle orderBy).
const getExercises = () =>{
return (
await ctx.db.query.exercises.findMany({
with: {
data: { orderBy: (data, { asc }) => [asc(data.doneAt)] },
position: true,
},
})
).sort((a, b) => b.position.gridPosition - a.position.gridPosition);
//^ how could I move this logic to an orderBy clause ?
}
const getExercises = () =>{
return (
await ctx.db.query.exercises.findMany({
with: {
data: { orderBy: (data, { asc }) => [asc(data.doneAt)] },
position: true,
},
})
).sort((a, b) => b.position.gridPosition - a.position.gridPosition);
//^ how could I move this logic to an orderBy clause ?
}
So how could I order my final result by it's grid position ? I have tried the following but without any luck:
const getExercises = () =>{
return (
await ctx.db.query.exercises.findMany({
with: {
data: { orderBy: (data, { asc }) => [asc(data.doneAt)] },
position: true,
},
orderBy: () => sql`exercises.grid_position`,
})
);
}
const getExercises = () =>{
return (
await ctx.db.query.exercises.findMany({
with: {
data: { orderBy: (data, { asc }) => [asc(data.doneAt)] },
position: true,
},
orderBy: () => sql`exercises.grid_position`,
})
);
}
2 replies
DTDrizzle Team
Created by Augustin Sorel on 10/5/2023 in #help
Drizzle update enum
No description
1 replies