datomic

braai engineer 2025-06-12T09:16:34.271939Z

Can datomic.api/index-range be used to efficiently count the number of matching values in a range, or do you need to take-while + drop-while to count?

favila 2025-06-12T10:56:17.654949Z

Index-range is efficient in that it only reads what you consume out of it. But I don’t get the connection to your second question

braai engineer 2025-06-12T10:57:12.525129Z

they are distinct questions: I was hoping there was a way to count the index size for matching values in an index without materializing it. The second question is about pagination.

favila 2025-06-12T10:58:29.478939Z

What do take while and drop while have to do with counting?

Joe Lane 2025-06-12T12:22:16.845299Z

Take the guts of group-by and create a new fn called reduce-by where the rfn is inc

braai engineer 2025-06-12T13:07:36.432219Z

Right, I was hoping there was a way to calculate (or even estimate) the size of matching values in multiple ranges without iterating over each datom in the range. My goal is to show a total count of matching values in an index without looping over every datom in index, which could be large.

favila 2025-06-12T13:14:51.494309Z

To estimate count without reading datoms would have a margin of error of over a thousand

favila 2025-06-12T13:16:17.625749Z

Have you tried index range? Getting a count of a contiguous section of index using index-range/seek-datoms is pretty darn fast

Joe Lane 2025-06-12T13:53:24.178089Z

Can you say more about how you determine if a datom's value "matches"? I assume when you said "the size of matching values" you mean "the count of matching values"?

braai engineer 2025-06-12T09:49:23.764809Z

Cursor-based pagination with d/index-range: is it possible to fetch the previous value in the range, i.e. (take 1 (reverse the-index)) knowing the current cursor value?

favila 2025-06-12T10:57:19.288239Z

No, only index-pull can read indexes in reverse

braai engineer 2025-06-12T11:00:57.909739Z

it seems that d/index-pull can only traverse the main indices :avet or :aevt, but not tuple indices

favila 2025-06-12T11:01:52.104989Z

“Not tuple indices” what do you mean? Avet and aevt can have tuples in them

favila 2025-06-12T11:02:36.514029Z

There’s no special “tuple indexes”

favila 2025-06-12T11:03:19.512069Z

Index-range is just wrapper for seek-datoms :avet

favila 2025-06-12T11:03:26.966789Z

It’s not special

braai engineer 2025-06-12T11:04:26.071189Z

ah, so the :selector can contain a tuple attr

favila 2025-06-12T11:04:36.358019Z

Yes

favila 2025-06-12T11:05:47.782549Z

But also not sure why that is relevant

favila 2025-06-12T11:05:56.179219Z

Selector is a pull expression

favila 2025-06-12T11:06:21.167909Z

Did you think pull expressions could not have tuple-valued attrs in them?

braai engineer 2025-06-12T13:06:03.176269Z

In my implementation, I'm destructuring the composite tuple value :v value to get at the data I need. Is d/index-pull sophisticated enough to know it can do that, or would it have to hit :eavt with the :e of the tuple attr to pull out the relevant :v?

favila 2025-06-12T13:11:37.823399Z

I believe the impl today performs a separate pull per entry hitting eavt or aevt and doesn’t reuse the value found. However this isn’t significant overhead if you are only taking a single item

vc 2025-06-12T10:51:39.248939Z

wild thought - is it possible to use supabase as storage for datomic? i don't see a reason why it won't be. does anyone use? ig cost could be a blocker but otherwise very much possible.

cormacc 2025-06-12T14:51:51.646659Z

It's just postgres, so probably? I'm using it as a transaction log for datascript (persisted to indexed-db, then synced to supabase) in a playground project, but no idea how it will scale.