datomic

jyn 2025-12-08T00:29:17.922309Z

what tutorials or resources do you suggest for learning datomic? i have some (rusty) SQL knowledge and i am reasonably familiar with data modeling in clojure, but https://docs.datomic.com/schema/schema-reference.html feels kind of overwhelming πŸ˜…

souenzzo 2025-12-08T09:50:09.435119Z

Some nice links https://learn-some.com/ https://tonsky.me/blog/unofficial-guide-to-datomic-internals/

😍 1
jyn 2025-12-08T11:42:13.406449Z

> Take care that they aren't too long how long is β€œlong”? they won't be more than 2 MB or so because at that point they'll hit ARG_MAX anyway

souenzzo 2025-12-08T11:44:39.214219Z

I think that in datomic cloud the limit is 4kb? Or 4mb? In datomic on-prem there is no limit - but you will have performance issues//it will require to tweak configurations to make it work.

jyn 2025-12-08T11:48:04.836029Z

the docs say 4k. ok, this is manageable, i can store larger command lines as response files and that’s probably a better design anyway.

jyn 2025-12-08T11:51:19.552879Z

the max overall size of the DB is around 20 GB (https://groups.google.com/g/android-building/c/CGZRqcRFtkk) and if that happens i'll have succeeded beyond my wildest dreams lol

jyn 2025-12-08T12:12:15.175709Z

> When in-memory index gets too big (memory-index-threshold, e.g. 32 Mb), transactor starts current index re-built. It is done by merging latest current index with in-memory index how does persistence work for the in-memory index? is it crash resistant?

Dave Liepmann 2025-12-08T12:34:12.909179Z

> β€’ Strings are limited to 4096 characters in Cloud and Datomic Local. Datomic does not enforce this limit in Pro, but users are strongly encouraged to enforce it. https://docs.datomic.com/schema/schema-reference.html#notes-on-value-types

Dave Liepmann 2025-12-08T12:36:33.681219Z

The important thing to keep in mind is that Datomic is designed to store facts, which it stores in covering indexes chunked into large segments. Large values increase the size of those segments in storage and take up memory whenever you read something "nearby" in the index.

πŸ‘ 1
Dave Liepmann 2025-12-08T12:55:30.997639Z

re: in-memory index, see https://docs.datomic.com/indexes/background-indexing.html and https://docs.datomic.com/operation/caching.html Rich also discusses the architecture at https://youtu.be/Cym4TZwTCNU?si=6TtVbIWrQT3zBtsu&t=2109.

jyn 2025-12-08T13:03:48.472309Z

oh interesting, the value types page mention that datomic does have tuples but they can be at most 8 values long

jaret 2025-12-08T14:36:32.809429Z

> how does persistence work for the in-memory index? is it crash resistant? If process dies, "in-memory" is blown away and picks up when you re-launch process (transactor) because it goes off what is durably written and can still identify novelty.

πŸ‘ 1
onetom 2025-12-09T06:59:12.050449Z

https://stackoverflow.com/questions/44645938/how-to-implement-sorted-to-many-relationships-in-datomic soultion 3's link is broken, but the accepted answer has a newer link to the same thing, i guess: https://github.com/dwhjames/datomic-linklist then other answers also mention datofu (https://github.com/vvvvalvalval/datofu), which has a few more useful facilities.

jyn 2025-12-08T00:30:48.246219Z

https://docs.datomic.com/reference/best.html is not exactly what i'm looking for but it's close

jyn 2025-12-08T00:36:54.279359Z

oh this is helpful https://docs.datomic.com/reference/entities.html

wevrem 2025-12-08T01:04:06.118829Z

There are these tutorials that helped me. https://docs.datomic.com/tutorial/tutorials.html

jyn 2025-12-08T01:07:08.569399Z

it doesn't have very much about schemas πŸ˜“ https://docs.datomic.com/client-tutorial/client.html#transact-schema

jyn 2025-12-08T01:07:20.121879Z

i'm trying to figure out how to model ordered lists and it seems ... quite complicated

wevrem 2025-12-08T02:02:11.103309Z

Maybe or maybe not helpful to you: I have some objects in my schema that the user can arbitrarily sort, so I just have this generic attribute that I can attach to any of these objects as needed:

{:db/ident           :item/sort-key
  :db/valueType       :db.type/long
  :db/cardinality     :db.cardinality/one}
Then of course I have to have logic to update the value when the user moves things around. And also logic to determine the next available sort-key when a new object is inserted.

JosΓ© Javier Blanco Rivero 2025-12-08T02:14:24.024319Z

Try https://max-datom.com/

favila 2025-12-08T02:24:01.082719Z

> trying to model ordered list congratulations on picking far and away the hardest db modeling problem

πŸ‘ 1
πŸ˜„ 3
πŸ˜“ 1
jyn 2025-12-08T02:31:38.764849Z

maybe i should just serialize EDN into the database or something idk

jyn 2025-12-08T02:31:46.606379Z

i don't actually need to query it, just store it

jyn 2025-12-08T02:32:08.316029Z

> Try https://max-datom.com/ this is adorable omg

jyn 2025-12-08T02:41:15.546639Z

maybe another thing to ask: datomic schemas seem very verbose to me, even compared to SQL. is that just normal, i'm not missing anything?

okwori 2025-12-08T03:13:14.157179Z

Maybe less verbose:

(defn- attr
  ([ident type cardinality] (attr ident type cardinality nil))
  ([ident type cardinality doc] (attr ident type cardinality doc nil))
  ([ident type cardinality doc more]
   (let [type (keyword "db.type" (name type))
         cardinality (keyword "db.cardinality" (name cardinality))
         more (if doc (assoc more :db/doc doc) more)]
     (merge {:db/ident ident
             :db/valueType type
             :db/cardinality cardinality}
            more))))

(defn- component
  "A component attribute"
  ([ident cardinality]
   (dissoc (attr ident :ref cardinality "" {:db/isComponent true}) :db/doc))
  ([ident cardinality doc]
   (attr ident :ref cardinality doc {:db/isComponent true})))

(def test-schema ;; define & add more related attr
  [(attr :test/name :string :one "The name of test")
   (attr :test/joined-at :instant :one "When test was created")
   (component :test/children :many "The children to carry with test")])

(def schema
  (vec (concat test-schema
               [(attr :transaction/namespace :string :one "Which namespace initiated the transaction")])))

(defn install-schema! [conn]
  (d/transact conn {:tx-data schema}))

😍 1
Dave Liepmann 2025-12-08T07:07:55.768209Z

> maybe i should just serialize EDN into the database or something idk Take care that they aren't too long. Large strings (or bytes for that matter) are not suitable for storage in Datomic. Better to store large values somewhere else (e.g. s3) and store the pointer as a datom.

πŸ‘† 1
robert-stuttaford 2025-12-09T14:53:57.633089Z

something to throw in the mix is that if you want to leverage composite key tuples for uniqueness constraint purposes, all the member attributes need to be together on the same entity. a contrived example: won't work because the values are on different entities

:partner/user REF to :user/* entity
:user/partner-external-id STRING
will work because they are together on the same entity
:user/partner REF to :partner/* entity
:user/partner-external-id
:user/partner+external-id-tuple :db/tupleAttrs [:user/partner :user/partner-external-id]
feel free to come back to this one once you're feeling more comfortable with the basics πŸ˜„