datalevin 2026-01-26

If conn is my connection atom, created with d/get-conn , what is the idomatic way to re-open a closed connection? Is there any need to (reset! conn ..) , or even something like (alter-var-root #’conn (constantly (get-conn))) to maintain a functioning reference to conn atom? Is this kind of userland connection management necessary in practice? I got tripped up with the semantics of if i reset conn to nil on closing, but the re-instantiate the connections with (reset! conn @(get-conn)) , but not sure if that was valid. Is connection management like this the same in Datascript and Datomic? I can look for documentation/tutorials there.

You manage a Datalevin connection like you manage a RDBMS connection. It is a stateful resource that you share around. If a conn is closed, create a new one when you need one. The commonly recommended approach is to use one of the several component management systems in Clojure, components, integrant, etc., if you want a lifecycle management solution. For simple use, just create a connection when you need one. Close it when you don't. There's no such thing as resetting a connection. To be honest, all those "db as a value" talk is just making people confused.

Ok, thanks.