Corbi-Wan Kenobi
Corbi-Wan Kenobi
CCConvex Community
Created by Corbi-Wan Kenobi on 1/26/2025 in #support-community
Using pagination in convex vs something like TanStack Tables?
As I think it through, I could get away with an infinite scroll table, technically. In my app this list of devices is in a table. Come to think of it, (not a convex questions strictly) can you make a <table> that is infinite school? Pardon the ignorance, I've just never messed with infinite scroll results before. Offset pagination is a relatively simple prospect in other databases that take things like limit and offset nativly. Not a dis on convex, just a learning curve thing.
22 replies
CCConvex Community
Created by Corbi-Wan Kenobi on 1/26/2025 in #support-community
Using pagination in convex vs something like TanStack Tables?
@lee Hey there. I'm back to this. I'm getting a "tree is empty" error. Would you be able to whip up a version of your photos offset-based pagination example, but instead of sorting by _creationTime it was based on the album name? That's basically what I'm doing, whole table sorted by one field that is (in my case) always unique (or maybe first sorted by album name then by _creationTime as a tie breaker). This is what I'm using to call for the data. const { data } = useSuspenseQuery( convexQuery(api.devices.paginatedDevices, { offset: 0, numItems: 10 }), ); Also, once I get results, can I use either the native pagination functions, and/or the getPage helper functions? Or neither and add in some kind of offset+ to generate sets and links to sets of pages of results?
22 replies
CCConvex Community
Created by Corbi-Wan Kenobi on 1/26/2025 in #support-community
Using pagination in convex vs something like TanStack Tables?
Thank you! I thought that' looked weird. That got me through that set of red squiglies. Thanks so much. Now some other stuff to fix. I really want to be as convex centric as I can. I already had a TanStack Table working, but I'd like to see this work as well. Thanks for your help and patience.
22 replies
CCConvex Community
Created by Corbi-Wan Kenobi on 1/26/2025 in #support-community
Using pagination in convex vs something like TanStack Tables?
OK, sorry, so I'm still missing something obvious. there is something still keying off if _creationTime. const theDevices = new TableAggregate<{ Key: string; DataModel: DataModel; TableName: "devices"; }>(components.theDevices, { sortKey: (doc) => doc.asset_tag, }); export const paginatedDevices = query({ args: { asset_tag: v.string(), offset: v.number(), numItems: v.number() }, returns: v.array(v.string()), handler: async (ctx, { asset_tag, offset, numItems }) => { const { key } = await theDevices.at(ctx, offset); const devicesRows = await ctx.db .query("devices") .withIndex("by_assetTag", (q) => q.eq("asset_tag", asset_tag).gte("asset_tag", key), ) .take(numItems); return devicesRows.map((device) => device._id); }, });
22 replies
CCConvex Community
Created by Corbi-Wan Kenobi on 1/26/2025 in #support-community
Using pagination in convex vs something like TanStack Tables?
Right now whole table of devices sorted by asset_tag which is unique and never empty
22 replies
CCConvex Community
Created by Corbi-Wan Kenobi on 1/26/2025 in #support-community
Using pagination in convex vs something like TanStack Tables?
It's confusing because I don't know what I'm doing yet. 🙂 From my devices schema - .index("by_assetTag", ["asset_tag"]), Can the asset_tag be the namespace and the sortKey?
22 replies
CCConvex Community
Created by Corbi-Wan Kenobi on 1/26/2025 in #support-community
Using pagination in convex vs something like TanStack Tables?
Is the sorting for offset pagination limited to _creationTime? I'm using the photos example and putting in the fields I want to sort on, but no matter what I get a TypeScript error saying that the value I want to sort is is not assignable to parameter type _creationTime. None of the fields I'm referencing for namespace, sortKey have anything to do with _creationTime. My indexes are all strings. I'm basically subsituting the _id for the album and the asset_tag for the _creationTime. const theDevices = new TableAggregate<{ Namespace: string; Key: string; DataModel: DataModel; TableName: "devices"; }>(components.theDevices, { namespace: (doc) => doc._id, sortKey: (doc) => doc.asset_tag, }); export const paginatedDevices = query({ args: { _id: v.string(), offset: v.number(), numItems: v.number() }, returns: v.array(v.string()), handler: async (ctx, { _id, offset, numItems }) => { const { key: assetTag } = await theDevices.at(ctx, offset, { namespace: _id, }); const devicesRows = await ctx.db .query("devices") .withIndex("by_assetTag", (q) => q.eq("_id", _id).gte("asset_tag", assetTag), ) .take(numItems); return devicesRows.map((device) => device._id); }, });
22 replies
CCConvex Community
Created by Corbi-Wan Kenobi on 1/26/2025 in #support-community
Using pagination in convex vs something like TanStack Tables?
Yeah, I found ways to build it programaticaly based on that, I just didn't know if there was anything already built in to the getPages that would do that.
22 replies
CCConvex Community
Created by Corbi-Wan Kenobi on 1/26/2025 in #support-community
Using pagination in convex vs something like TanStack Tables?
No description
22 replies
CCConvex Community
Created by Corbi-Wan Kenobi on 1/26/2025 in #support-community
Using pagination in convex vs something like TanStack Tables?
Doing some re-reading of the convex docs and somehow just now found the stack articles on both.
22 replies
CCConvex Community
Created by Corbi-Wan Kenobi on 1/25/2025 in #support-community
How to tell the query to include specific fields
OK. I've taken what you've given me, which works thanks again, and reworking it from the outside in to both learn how/why it works, and to customize it a bit more. Agreed, it is very zippy.
10 replies
CCConvex Community
Created by Corbi-Wan Kenobi on 1/25/2025 in #support-community
How to tell the query to include specific fields
I'm mean if that's the way it is, then that's the way it is. I can work with it. Just seems like a lot of work on the other end to filter out. In the thing you have been helping me with, I want to limit the fields returned, but it seems to break the stacked/nested queries.
10 replies
CCConvex Community
Created by Corbi-Wan Kenobi on 1/25/2025 in #support-community
How to tell the query to include specific fields
Doesn't that seem like it would be a hit on efficiency?
10 replies
CCConvex Community
Created by Corbi-Wan Kenobi on 1/24/2025 in #support-community
Joining related tables help
@ian @erquhart Thank you both. I need a nap now. 🙂
38 replies
CCConvex Community
Created by Corbi-Wan Kenobi on 1/24/2025 in #support-community
Joining related tables help
That was very helpful. Some of the 10,000ft level things make more sense now. My main obstacle is understanding how to write one (or more) statements that give me a joined result. @ian could you look at this post here from above and tell me what you would do? Again, doing these things progamatically(?) and not in an ORM or more SQL way is new to me. But once I see a complete end-to-end working example I'm usually pretty good and translating that to other use cases. https://discord.com/channels/1019350475847499849/1332146850546847764/1332438783609667607
38 replies
CCConvex Community
Created by Corbi-Wan Kenobi on 1/24/2025 in #support-community
Joining related tables help
I'm using TanStack Start (which convex has a module that is a mini-TanStackQuery) as my framework and the convex docs related to that are pretty bare bones, so no I have not done the chap app tutorial yet as it seemed I would need to use a different framework. But it looks like a pure React app anyway so maybe its moot. Trying not to mix too much stuff into my tiny brain. But I might do it now that you've mentioned it just to take a break and glean some pieces.
38 replies
CCConvex Community
Created by Corbi-Wan Kenobi on 1/24/2025 in #support-community
Joining related tables help
I'm rereading Ian's post on Stack right now. It's fleshed a few things out better that I'm trying to piece together.
38 replies
CCConvex Community
Created by Corbi-Wan Kenobi on 1/24/2025 in #support-community
Joining related tables help
@erquhart Is the convention in the helpers that the const thisRightHere should be the same as the name of a table being referenced? const people means the statement is referring to the people table?
38 replies
CCConvex Community
Created by Corbi-Wan Kenobi on 1/24/2025 in #support-community
Joining related tables help
You know, I think I figured out part of my problem. In some parts of the docs there is given a block of code that is the longer non-helpers version of a query followed by one-liner equivalent that is the helpers version of the same thing. In other parts, there is a longer block given, but the one-liner that follows is a substitute for the last line only of the longer block, not the entire block. And yeah, I wasn't 100% on the getManyVia but it looked like the closest. I took Spanish in High School, wasn't great at it. I took French in college and could only remember more Spanish that I'd forgotten than I could learn French. That's what this feels like. Coming from SQL the relative simplicity of a one-liner select statement is easy and fresh. Still trying to bridge this gap and I really appreciate your patience and help.
38 replies
CCConvex Community
Created by Corbi-Wan Kenobi on 1/24/2025 in #support-community
Joining related tables help
@ian can you chime in on this thread now that I have posted a schema and a specific use case?
38 replies