Ask questions on the official Q&A site at https://ask.datomic.com!
Huahai 2020-12-12T17:42:57.114700Z

how to do something equivalent to SQARQL OPTIONAL in datomic?

favila 2020-12-12T19:04:06.114800Z

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

favila 2020-12-12T19:05:19.115Z

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

favila 2020-12-12T19:05:44.115200Z

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

favila 2020-12-12T19:05:54.115400Z

(for any given thing you are checking)

favila 2020-12-12T19:06:59.115600Z

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

favila 2020-12-12T19:07:08.115800Z

namespaced-keywords work well IME

favila 2020-12-12T19:07:33.116Z

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