Fork me on GitHub
#asami
<
2021-10-09
>
william15:10:58

@quoll I'd like an opinion; I have an in-memory db with asami, and from some of the query in that database I'd like to create some visualizations (using reagent). What's the best way of syncing a r/atom to a query in my in-memory db in your opinion?

william15:10:55

To be more clear, I'd like that when I do a transaction, the query that powers a r/atom is redone, so that redrawing is triggered on the js side

william15:10:45

maybe there's even a library that does this kind of integration for reagent?

quoll15:10:04

I don’t think there is (I certainly haven’t done it)

quoll15:10:19

There’s currently no hook for a transaction to execute code when it’s done. Typically, I’ve created my own transaction function to wrap the central one, though I know that doesn’t always work.

quoll16:10:20

At this point, I would recommend putting a watch on the Connection state field (which is an atom)

quoll16:10:15

So if you have a connection called c then: (add-watch (:state c) :your-key your-fn)

quoll16:10:40

The state atom contains a map with 2 values:

{:db latest-db-value
 :history [...]}
The history is an array of all the previous DB values

quoll16:10:15

I realize that this is unsatisfactory. It’s incentive for me to add a transaction function post haste

quoll16:10:43

Anyway, every call to transact will lead to this atom being updated. The :db value will change to have the updates in it, and the :history value will grow 1 longer

quoll16:10:31

This will take more effort than a simple hook, but would you be interested in seeing this whole API? https://docs.datomic.com/on-prem/reference/database-functions.html

william16:10:38

thank you so much for the explanation @quoll! In my case I can probably work around the problem with a watch as you suggested. I mostly don't want to cause any urge since I know that you're not working on this directly in these days. Ideally from the API you linked I really like having the possibility to specify checks and constraints, but I'm not very familiar with it - watching the video now :)

quoll16:10:17

Oh? Which video?

william16:10:37

https://www.youtube.com/watch?v=8fY687k7DMA which was linked in the page you suggested

william16:10:24

it's a very nice idea, and I didn't realize that asami tends to the same API of datomic! Neat!

william16:10:06

anyway, if you ever end up implementing the hook feature ping me - also, if you want to pair on the issue I'm up for it

quoll16:10:37

generally. The idea was to make it easier for people to try using it

lilactown18:10:20

can asami dbs be used as immutable values? i.e. w/o a connection container

lilactown18:10:27

w/ datascript you can eschew the whole “conn” and just use db-with which returns a new db value. this way you can store it in your own container, like a reagent ratom

quoll19:10:33

Yes. Databases are an immutable value

quoll19:10:19

You can easily wrap them in a new connection and they will be a db-with value

quoll19:10:58

I can’t do that with persisted databases though. (well, I could, but that would create a branch, and I have no idea how to resolve branches!)

william23:10:38

can you show me how this technique would look like? I mean, using in-memory databases as values without using the connection abstraction?

quoll03:10:16

Databases (retrieved via (asami.core/db my-connection) or (asami.core/as-of some-db some-time) etc) are already a value, and can be queried. You can make it a connection that can be transacted against with: (asami.memory/new-connection “asami:” my-db)

🙌 1