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:
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:
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.
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:
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:
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