datalevin

weavejester 2025-09-19T12:49:03.084019Z

I've been looking into Datalevin, and I'm unsure of the best way to store insertion order of entries. In SQL I'd use an auto-increment column. In Datalevin (and Datomic), I've considered maintaining a counter field that I update within a transaction, and I've also thought about using a sequential ID algorithm like Flake. Is there a better, more idiomatic option that I'm missing?

weavejester 2025-09-21T12:47:36.069189Z

Thanks for the advice! That's the conclusion I was coming to as well. I guess what I really want is a deterministic time ordering, so I could sort by timestamp then ID to resolve any potential conflicts.

Max 2025-09-21T14:20:44.363299Z

Yeah that’s what I would do. Honestly I’d do the same thing in SQL too, At least with Postgres, sequences can get out of order or skip due to a variety of reasons.

Max 2025-09-21T02:59:28.404849Z

I'm not sure about datalevin specifically, but in Datomic you'd use a https://docs.datomic.com/transactions/transaction-functions.html#writing that first queries the highest existing id, increments it, then stores it. It seems like Datalevin has https://cljdoc.org/d/datalevin/datalevin/0.9.22/doc/transaction#transaction-functions-in-datalog-store. That said, I would strongly recommend against data models that need to maintain insertion order. I've certainly done this to meet very specific business requirements, but it's a pain and should be avoided if at all possible.

Casey 2025-09-19T05:27:52.097529Z

Does datalevin come with the same caveats for long string values like datomic? (Curious about datalog and KV mode)

Josh 2025-09-19T13:12:56.223119Z

Per the limits https://github.com/juji-io/datalevin/blob/master/doc/limits.md individual value size can be 2 GB

Josh 2025-09-19T13:13:40.398979Z

I store fairly large strings in datalevin with no issues, I do not use the search index though