Fork me on GitHub
#asami
<
2021-09-24
>
Carlo23:09:20

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?

Carlo00:09:14

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

quoll01:09:05

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

quoll01:09:04

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

quoll01:09:26

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

Carlo14:09:08

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

quoll19:09:41

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?

Carlo23:09:17

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?

quoll00:09:17

Yes. Generating queries is definitely a good reason!

🙌 1