amppA
Convex Community2y ago
5 replies
ampp

Advanced index usage

I don't understand why I can't do any of this with a index. I didn't see in the docs a explicit explanation that you couldn't do something like this using the available .eq,gt,gte,lt,lte so i tried a few things.
assume ['by_index1_index2_index3']
(q) => q
  .gt('index1', null
  .eq('index2', index2)
  .gt('index3', '2')
  .lt('index3', '4')

(q) => q // just ignore index1 enitrely
  .eq('index2', index2)
  .gt('index3', '2')
  .lt('index3', '4')

(q) => q 
  .eq('index1', index1)
// just ignore index2 but use to sort. 
  .gt('index3', '2')
  .lt('index3', '4')

(q) => q 
  .eq('index1', index1)
  .gt('index2, '1'
  .gt('index3', '2')
  .lt('index3', '4')

(q) => q 
  .eq('index1', arrayOfOptions)
  .eq('index2, '1'
  .gt('index3', '2')
  .lt('index3', '4')

neq would solve some of this.. but how can just getting all of a index break things too.
Is any of it going to be supported or just via that eventual sql style "adapter"

In one real world example i have a events table with ['lastStatus', 'userid', 'eventType'] where i also have have a index [ 'userid', 'eventType'] when i want all statuses from that user. A gte null on lastStatus index would keep me from duplicating effort.

Probably the most annoying one is to get the last 10 results since a certain time while getting a range of eventTypes for a user ['recordedAt', 'userid', 'eventType']

I fail to see how anyone could ever use more than a few indexes if all but the last one requires .eq usage. I certainly cant imagine complex use cases, I'd love to see some real world work arounds. Or how others here are creating separate tables etc to get more specific.
Was this page helpful?