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

What would it take to abstract the storage? #1

Open
drewverlee opened this issue Nov 16, 2020 · 5 comments
Open

What would it take to abstract the storage? #1

drewverlee opened this issue Nov 16, 2020 · 5 comments

Comments

@drewverlee
Copy link

My understanding from the readme is that what rule/data is implemented/backed via a clojure atom. Roughly, what do you think it would take to abstarct the storage? in my specific use case, i'm considering what it would take to back odoyle with datomic cloud. Do you see any obvious blockers or refactors?

Thanks for any input!

@oakes
Copy link
Owner

oakes commented Nov 17, 2020

The library itself doesn't actually care how you store it. All the examples use atoms, but the library has no built-in assumptions about that. The functions like insert and retract just expect the session to be provided, and return a new one, so you can store it in any container you want.

As for datomic, it should be possible. I assume you want to store the matches for a given rule in your datomic db. You can get all the matches for a given rule like this:

(def rules
  (o/ruleset
    {::character-position
     [:what
      [id ::x x]
      [id ::y y]
      :then-finally
      (println (o/query-all o/*session* ::character-position)) ; [{:id :player :x 10 :y 10} {:id :monster :x 1 :y 5} {:id :boss :x 15 :y 0}]
      ]}))

So in theory you could replace that println call with a function that stores that vector in datomic. Every time any character's position is updated, the :then block will be called again, and you'll be able to update the vector in datomic.

You will probably still need to keep the session in some kind of container though. Locally you'll need to keep the session in an atom, volatile, or something like that. But every time you update it, the :then blocks will fire and cause the data to go into your db.

@oakes
Copy link
Owner

oakes commented Dec 4, 2020

As of version 0.5.0 you can now query all the individual facts from a session, so that might be a better way to store them in datomic. All you do is run (query-all session) and it'll return the facts as [id attribute value] tuples, which could then be directly stored in datomic. I added a section to the readme called "serializing a session" which talks about this.

@allentiak
Copy link

@oakes Could you please either document this storage functionality a little bit, or point to examples?

@oakes
Copy link
Owner

oakes commented May 11, 2021

If you mean how to serialize sessions, i wrote about it here: https://github.com/oakes/odoyle-rules#serializing-a-session

@allentiak
Copy link

Thanks for the pointer!

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

3 participants