index order not as expected
Hey gang. I am building a table with sort functionality but am running into an issue the ordering.
here is the exact code:
let sortedBlockAttributes = await ctx.db
.query("block_attributes")
// adding the group attribute and value to the index below orders the results relative to
// the sort. We don't need to add a value to them because we only care about the order.
.withIndex(
"by_parent_group_id_organization_id_group_attribute_id_value",
(q: any) =>
q
// @ts-ignore
.eq("parent_group_id", args.rows)
// limiting block_attributes to ones with a corisponding parent_group_id prevents timeouts
.eq("organization_id", primaryGroup.organization_id)
)
//@ts-ignore
.order(args.sort?.[0]?.direction || "asc")
.take(12000);
blockIds = sortedBlockAttributes.map((ba) => bs.parent_block_id)
}
here is the schema for the "block_attributes" table:
block_attributes: defineTable({
organization_id: v.id("organizations"),
group_attribute_id: v.id("group_attributes"),
parent_group_id: v.id("groups"),
parent_block_id: v.id("blocks"),
value: v.any(),
meta: v.optional(v.any()),
})
.index("by_parent_group_id_organization_id_group_attribute_id_value", [
"parent_group_id",
"organization_id",
"group_attribute_id",
"value",
])
Provided a parent_group_id and an organization_id, this code is intended to return all rows in a convex table sorted by value (in this example all entries int he tabel have the same group_attribute_id)... however the results (a list of Unix epoch time stamps) come back out of order.
I have been up all night trying to get this to work so there is a > 0 chance I am just doing something dumb. Either way I would love some advice from a more experienced/well rested brain lol2 Replies
Nothing is jumping out at me, but Iād first recommend getting rid of those ts-ignores, as you may be silencing the answer to your question.
Agree with @erquhart that
q:any
and @ts-ignore
is a big red-flag of something else is going on with this
If I were you, try removing those and then trust the TS compiler and walk through it š