Fork me on GitHub
#xtdb
<
2020-12-05
>
dominicm06:12:35

Does crux support filtered dbs?

refset11:12:59

No, not yet as a core API. You can achieve something similar, an eager filter, by using a transaction function inside a with-tx call that deletes entities you don't want to be visible to queries. It's not a terribly scalable approach but could still be useful for some

refset11:12:09

Are you thinking to create isolation between tenant data or something? Another approach could be to decorate your queries with parameterized rules

dominicm14:12:33

I was thinking of permissions, so like a tenant system. Yeah. Wrapping ICruxApi and adding rules would help.

refset16:12:46

@U050CTFRT and I got quite far with implementing such a rules system to support XACML and GDPR permissions (which isn't really possible via filters), e.g.

(let [db (crux/db (dev/crux))]
    (crux/q
     db
     (entail
      db
      {:find '[?data]
       :args '[{?user :ex/alice
                ?patient :ex/bob}]
       :where '[
                ;; Get medical record events relating to patient
                [?data :juxt.rdf/type :hl7.type/medical-record-event]

                ;; But only according to GDPR rules
                [?data :gdpr/subject ?patient]
                [?user :works-for ?dp]
                (gdpr/can-legitimately-process? ?dp ?data)
                ]

       :rules RULES}))))
It might be worth a quick show & tell 🙂