datomic

tatut 2025-05-28T09:22:28.699749Z

https://forum.datomic.com/t/handling-ordered-lists/305 I guess this is still valid? I want an ordered list of refs, the items have no inherent order, so one item can be in many different lists in separate positions... so I would need a separate entity that keeps the ref and position in list, or serialize

👍 1
tatut 2025-05-28T09:23:33.873189Z

the case I'm planning, I don't think I would need to really query inside them... just load this (seldom changing) data once and it is cached in my application's memory... so I'm tempted to just use bytes to serialize the long id numbers

tatut 2025-05-28T10:04:07.132549Z

also the lists are mostly short (at most tens, definitely not hundreds of entries) so the 4k size limit of single value isn't close

cch1 2025-05-28T14:11:02.225769Z

I think the perspective is still valid. @favila and I had some deep conversations somewhere in this channel about the fundamental difficulties in managing "human-friendly" sequential identifiers in Datomic. I think indices fall into that category as well. If your application can assign the indices safely (no possibility of race conditions from competing transactions) then you are in a happy place. If not, you will either need a transaction function to assign the next available index or use CAS to optimistically assign the likely next index. It's really not too hard for the basics. This assumes you use a position/index attribute to order your list.

favila 2025-05-28T14:13:38.493239Z

Thing I have done before is use bigint bigdec for variable-precision sort

cch1 2025-05-28T14:13:39.671839Z

It gets harder if you want to use human-friendly positions (e.g. 10, 20, 30...) versus plain numbers. It gets harder if the positions are scoped to some parent entity (think order lines scoped to an order). It gets harder if you want a transaction function to be generally useful for create or update.

favila 2025-05-28T14:14:19.815389Z

bigint bigdec means insertion between two items can bump precision instead of renumber a bunch of items

favila 2025-05-28T14:14:25.151519Z

it was much more complicated though

favila 2025-05-28T14:14:42.532209Z

not confident I could reimplement that blind right now

cch1 2025-05-28T14:15:15.396069Z

That's a neat trick!

refset 2025-05-29T00:57:33.341709Z

This lib does the 'bisection' / precision bump trick also, but with variable length strings https://github.com/Cumulo/bisection-key.cljs

1
Noah McMillan 2025-05-29T07:24:19.327279Z

It would be great to have some documentation on what is considered idiomatic in this context. I have an entity that has two references and an order number, but this structure doesn't feel idiomatic. I would have thought ordering would be quite common.

cch1 2025-05-29T14:07:11.093949Z

I have spent a lot of time in the past couple of months working on good practices and idioms for managing "order numbers" and dependent "order lines". It has not been easy and our current "best practice" might not be the same answer you get from others or even from my past and future selves. Order Numbers are identified by the :db.unique/identity attribute :order/number and assigned by a transaction function that uses an auxiliary entity to track the next available number in a series (orders can be numbered in series, e.g. the "10000 series" and the "20000 series"). Order numbers are longs. Order Lines are associated with orders two ways: one is via an isComponent attribute in the parent order and the other is via a tuple of [:order/number, :order.line/number]. The line numbers (multiples of 10) are assigned via a transaction function that knows how to scope the numbers to the parent order. The unique tuple is assigned by a separate tx-fn after the order and line numbers have been assigned. Coordinating these tx-fns for new and existing orders has been very difficult and has forced me to build out a whole infrastructure of tx-fns that allow for nicer composition than "plain" tx-fns. The net of it all is that we have replicated the common business model of order and lines with "human-friendly" numbering. I could go into much more detail on the pro and cons of each of the design decisions needed to reach this point but this post is getting too long. I'm happy to provide more context if you have a specific question.

👍 1
tatut 2025-05-30T05:32:26.838029Z

that bisection-key looks neat, you only have to change 1 attribute of 1 entity when changing the position inside a list

👍 1
💯 1
icemanmelting 2025-05-28T11:25:26.310229Z

Hey Guys, I was able to add datomic to a docker image (datomic peer server/transactor) and I am using docker scout to check vulnerabilities. It indicates that there are several severe vulnerabilities with outdate libraries. What is the correct procedure to update these? Should we just communicate that to the Datomic team, or is there an easy way to update these packages? Thanks for you guy's time