Fork me on GitHub

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?


it seems that asami.core/delete-database was what I was searching for 🙌


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)]


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?


Essentially I generate the queries at run=time, and the query language is a very good representation of what I want to say. As an added bonus, I can use d/q to actually use them against a db. Does it answer the question?


Yes. Generating queries is definitely a good reason!

🙌 1