Fork me on GitHub
#datascript
<
2022-05-02
>
folcon12:05:13

Hey, I'm looking at rules engines, that work with datascript. I've been digging into (https://github.com/frankiesardo/minikusari) I've been using it as a really nice way to manage application complexity which is really simple to understand as it's just a function. One thing I've been thinking about is performance, there's a pretty decent thread here[0] that covers datascript performance issues which I'm slowly reading through, as well as alternatives. Are there any solutions that people are aware of that are both a reasonably performant datastore and are compatible with "rule engines"? Btw, I'm not tied to this approach, if someone can suggest something more elegant, I'd be happy to give it a go šŸ˜ƒ... More detail in the thread, so I don't clutter up the channel! ā€¢ [0]: https://clojurians.slack.com/archives/C07V8N22C/p1615872613002600

folcon12:05:34

minikusari's implementation:

(defn r
  "Tries to match rule against db
  Returns tx-data or empty list if rule does not match"
  [{:keys [when then args]} db]
  (let [syms (for [row then el row :when (symbol? el)] el)
        results (apply d/q {:find syms :in (cons '$ (keys args)) :where when} db (vals args))]
    (for [match results tx then]
      (let [swaps (zipmap syms match)
            f (fn [x] (if (coll? x) x (get swaps x x)))]
        (walk/postwalk f tx)))))

jjttjj03:05:29

Have you seen https://github.com/oakes/odoyle-rules? It's not datascript/datalog compatible, but it's similar syntax

folcon19:05:22

Thanks @U064UGEUQ, that's the sort of thing I was thinking about.

šŸ‘ 1
Drew Verlee01:05:00

Let me know if you end up oaks library, I'm currently messing with it and I'm curious what other people think.

folcon19:05:02

At the moment I haven't, I've found that function I linked above is currently good enough. Once I've gotten a few more rules working and I want to see what the performance side of things looks like, then I'm planning on looking at odoyle-rules. My current plan (which maybe a terrible idea) is to benchmark it against sqlite in memory mode, my existing implementation (which it will probably beat handily). clara-rules and neanderthal. I'm aiming for a balance of performance and easy to maintain rules...

Drew Verlee20:05:44

What is the "it" your benchmarking? The fn above?

Drew Verlee20:05:02

I'm clueless, what would that have to do with sqlite?

folcon20:05:27

It is the function above šŸ˜ƒ

folcon20:05:30

sqlite would be another way of representing data in a consistent way and processing it using rules, in a similar format to what I'm doing with :when and :then semantics above. There are clojure libs that can turn datastuctures into sql statements and then I can take my rules (a list of sql expressions evaluated in order where if they return rows, what should be run against the result) as well as the application state (current db state) and basically that would be my application. Schemaverse is an example of an application built like that [0]. odoyle and clara do something similar, though they do some additional things as they're intended to be truth maintenance systems. I'm not yet certain that I ned the extra features this provides. ā€¢ [0]: https://github.com/Abstrct/Schemaverse

Drew Verlee22:05:54

I understand, thanks!

folcon22:05:07

You're welcome!