Fork me on GitHub
#datomic
<
2020-12-12
>
Huahai17:12:57

how to do something equivalent to SQARQL OPTIONAL in datomic?

favila19:12:06

[(get-else $ ?e ?attr ?non-nil-sentinel-value) ?captured-value]

favila19:12:19

or (or-join [?e ?v] [?e ?a ?v] (and (not [?e ?a]) [(ground "non-nil-sentiel") ?v)) for more complex cases

favila19:12:44

or use rules and make sure one implementation always matches and one never does

favila19:12:54

(for any given thing you are checking)

favila19:12:59

note unfortunately you can’t safely have nil values in your intermediate result sets so you usually have to replace it with some non-nil sentinel value

favila19:12:08

namespaced-keywords work well IME

favila19:12:33

and then postprocess the query result back to nil if you need it