asami

Carlo 2021-09-24T23:52:20.016400Z

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?

Carlo 2021-09-25T00:15:14.016500Z

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

quoll 2021-09-25T01:20:05.016700Z

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

quoll 2021-09-25T01:22:04.016900Z

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

quoll 2021-09-25T01:23:26.017200Z

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

Carlo 2021-09-25T14:53:08.018100Z

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

quoll 2021-09-25T19:51:41.018700Z

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?

Carlo 2021-09-25T23:45:17.030400Z

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?

quoll 2021-09-26T00:20:17.031500Z

Yes. Generating queries is definitely a good reason!

🙌 1