| My Clojure experience doesn't really help me with Datomic, although my knowledge of Clojure isn't very deep. That hard part about Datomic for me is that there's no book of best practices or any sort of cookbook that I'm aware of. For example, the first obvious thing you probably want in Datomic is an auto-incrementing ID. In fact, that's the first thought I probably had when I tried to run my first Datomic query: "Wait... my user doesn't have a unique ID". So the first order of the day was to create an auto-incrementing ID system, something I hadn't seen in the few tutorials I'd found (so it surprised me that I had to make one). But I found something called a "transaction function" in a blog post that sort of did what I needed and I came up with this: {:db/id #db/id[:db.part/user]
:db/ident :addUID
:db/fn #db/fn
{:lang :clojure
:params [db new-eid attr]
:code (let [res (datomic.api/q
'[:find (max ?uid)
:in $ ?attr
:where [_ ?attr ?uid]]
db
attr)
new-uid (inc (or (ffirst res) 0))]
[[:db/add new-eid attr new-uid]])}}
You pass it :user/uid, :topic/uid, :post/uid or whatever you may have, and it finds the max `uid` for all entities that have the `:user/uid` attribute. Then it either adds 1 to it or starts at 0 if none exist.But I didn't really know where to put that. So I copied a Stuart Halloway repo and put it in a `resources/data_functions.edn` file. And I copied DayOfDatomic's code that actually loads it: (defn create-db []
(d/delete-database uri)
(d/create-database uri)
(let [conn (d/connect uri)]
(transact-all conn "resources/schema.edn")
(transact-all conn "resources/data-functions.edn")
conn))
But my workflow for this kind of thing is still to just recreate the database from scratch since I'm not sure how to do it incrementally, like in a migration. And I restart the transactor every time.Moral of this story being that I'm just faking it til I make it. But despite all of this, I made it farther in Datomic with a couple resources than I would've made it with Postgres and Sinatra with a couple resources. And once you get some sort of good-enough, hilarious scaffolding up and running, it's easy enough to make incremental progress from there as you need it. If it helps, a while back I documented my first effort with Datomic where I built a database that stores author data from OpenLibrary[2]. But on second look, it's reallly long and aimless. Much like this post. [1]: http://www.danneu.com/posts/authordb-datomic-tutorial/ [2]: https://openlibrary.org/developers/dumps |
If you wanted something else, then why not just use a UUID to avoid relying on the DB?
Or if you are using a RDMS like postgres for datomic's underlying datastore, just manage a seq directly there.
One thing I have learned is trying to use one tool for every problem just creates a lot of headache.