Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Immutable API/db-wth support #20

Open
bahulneel opened this issue Feb 29, 2024 · 1 comment
Open

Immutable API/db-wth support #20

bahulneel opened this issue Feb 29, 2024 · 1 comment

Comments

@bahulneel
Copy link

Description

Asami is great for producing data-driven apps with arbitrary data sources, and it pairs well with other triple-based tools. I'm working on a library that uses Asami as its state atom. Currently, it uses the DB name to separate sessions/states. However, I would like to start being able to reuse earlier states and exploit Clojure's cheap persistent data structures for features such as incremental dataflow or pre-computing some expensive initial data set and then using the db value at this point as the initial db value.

Datomic and Datascript have the db-with function for this in-memory/speculative work.

Problem

Looking at the implementation of transactions in the repo, it's not too clear if such a thing exists or how one might roll their own. I've tried to bake a connection value based on the shape of the "atoms in an atom" connection, but it was a bit flakey and felt like a code smell. This also makes subscribing to updates non-trivial.

Suggested Approach

A separate functional API for in-memory graph values that leverages a db-with approach to transactions would provide a good balance between keeping the existing implementation and supporting this functionality. Such a thing may already exist if you know where to look, which, right now, I don't

I'm happy to be shown in the right direction to be able to implement this myself.

@bahulneel
Copy link
Author

I found this solution as a stopgap:

(defn copy-connection! [conn new-url]
  (let [[_ _ db-name] (re-find #"asami:([^:]+)://(.+)" new-url)
        new-conn (-> conn
                     (assoc :name db-name)
                     (update :state #(-> % deref atom)))]
    (swap! d/connections assoc new-url new-conn)
    (d/connect new-url)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant