This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-09-24
Channels
- # announcements (30)
- # asami (9)
- # babashka (37)
- # beginners (120)
- # calva (26)
- # cider (3)
- # clara (9)
- # clj-commons (7)
- # clj-kondo (17)
- # cljsrn (2)
- # clojure (32)
- # clojure-europe (56)
- # clojure-nl (1)
- # clojure-norway (13)
- # clojure-uk (4)
- # clojurescript (34)
- # conjure (1)
- # copenhagen-clojurians (8)
- # core-async (21)
- # cursive (2)
- # datahike (2)
- # datascript (5)
- # events (4)
- # fulcro (32)
- # graalvm (10)
- # heroku (3)
- # introduce-yourself (1)
- # jobs (2)
- # lsp (3)
- # luminus (1)
- # malli (8)
- # meander (15)
- # minecraft (1)
- # nrepl (2)
- # off-topic (57)
- # pathom (2)
- # polylith (35)
- # reagent (6)
- # reitit (8)
- # releases (1)
- # rewrite-clj (7)
- # shadow-cljs (21)
- # timbre (4)
- # tools-build (1)
- # tools-deps (33)
- # vrac (8)
Hmm, I wonder, what's the way of garbage collecting a database? Say I want to spin up an example database, do some transactions and some queries, then scrap it - the idiom could be something like (with-database ...)
. How would I do that?
Yes! When I saw the start of the question on my phone just now I was thinking of that. But when I saw that the rest of the question had a with-database
proposal, then I was thinking of a with-open
style macro
However, if you’re just spinning it up, doing transactions, then throwing it away, then you should use a database with a URL of the form:
asami:
In-memory databases are orders of magnitude faster. The only reason to use a local database (on disk) is if you:
a) need it to scale to GB
b) need to keep it
The on-disk databases are a bit slow to transact large amounts of data because they fully index all the data coming in. It makes for fast queries, and small updates are quick too
indeed, for what I have to do in-memory databases are perfect (for now, at least), especially because I want them to be transient. I'm currently using this:
(defn with-db [db-data db-query]
(let [db-uri (str (gensym "asami:-"))
conn (d/connect db-uri)
_ @(d/transact conn {:tx-data db-data})
res (d/q db-query (d/db conn))
_ (d/delete-database db-uri)]
res))
I know this works, because my colleagues do it a lot, but it also makes me wonder at what you’re looking for. You’re using the entity readers to convert the data to triple form and then query it, which is great, but if it’s a simple query then I wonder if there is a function which could work on the data just as well?