Fork me on GitHub

Hello, I am a beginner with Clojure and with Datascript. I hope this is the right place to post. I am writing a Clojure program that loads a JSON "knowledge graph" into memory and then loads the graph's nodes and edges into two Datascript databases (using d/db-with). That part is working fine. Now I want to query the Datascript databases. My program will not be modifying the databases; only querying them. Here is my question-- do I need to create a database "connection" using d/create-conn? I mean, I seem to be able to query the database without a "connection", like this

(d/q '[:find ?e :where [?e :id "biolink:affects_stability_of"]] kg2c-db-nodes)
but I am wondering if there is some performance advantage to creating a connection? Or is a "connection" only needed when a program needs to modify the Datascript database? Thank you.

Linus Ericsson10:01:08

The connection in datascript is (mostly) an atom pointing at the most recent datascript database. All indexes etc is in the datascript database object. There are not performance penalties on using only a datascript database without the connection.

👍 1

Thank you, Linus!


Yes; To add to @UQY3M3F6D's comment, it's worth noting that this works because datascript databases are persistent (immutable) data structures, so tracking state using a regular ol atom is both natural and idiomatic.

👍 1

Thank you, metasoarous


Ah, I found the page that describes atoms; I will read about them. Thank you!