Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I've been using it on my past few small projects where I would've otherwise used Postgres, so I mostly have CRUD-level experience with it with no meaningful insights within the rest of this comment.

The query interface (Datalog: http://www.learndatalogtoday.org/) is immediately refreshing, simpler, and nicer to write than SQL. Of course, you also get to use Clojure data-structures.

Datomic itself feels like the best of both worlds across relational and nosql databases. Although I often wonder if I'm even taking advantage of it since I'm still so table-brained.

For me, the hardest part about Datomic is that you're sorta on your own. Expect to do some internet-snippet window-shopping to throw a sensible db.clj namespace together. And be sure to peep Stuart Halloway's gists. Honestly, I still don't know a good strategy to migrate schema changes, my hand-rolled attempt at a db.clj abstraction is comically bad, and since I don't know the Right Way to do anything, I just throw in more `juxt` until things work. But it's all worth it.

There's no chorus of noobs to scavenge from nor have they trodden down the path before you. In fact, I think I'm the noob chorus. And instead of trailblazing a path for you, I've become stuck in the first bramblebush.

https://github.com/Datomic/day-of-datomic/tree/master/tutori... is the best resource I can point to.



"In fact, I think I'm the noob chorus. And instead of trailblazing a path for you, I've become stuck in the first bramblebush."

You are not alone. :)


Were you already experienced with Clojure? I am just starting out with Clojure, so datomic being such a young database makes things challenging.


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


I guess I don't understand why Datomic's entity id wouldn't work as your auto-incrementing id.

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.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: