<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Datomic Knowledgebase - Recent questions tagged query inputs</title>
<link>https://ask.datomic.com/index.php/tag/query%20inputs</link>
<description>Powered by Question2Answer</description>
<item>
<title>How to gracefully handle optional query inputs?</title>
<link>https://ask.datomic.com/index.php/616/how-to-gracefully-handle-optional-query-inputs</link>
<description>&lt;p&gt;How does one handle the following use case: I have a complicated report that allows the user to filter/narrow the results in a multitude of different ways. Let&#039;s say for example it&#039;s an order report. The user might want to view only the orders placed between yesterday and today, or they might only include orders placed by a particular customer, etc...&lt;/p&gt;
&lt;p&gt;Some of these query inputs have obvious defaults (eg the default date range can just be &quot;orders placed today&quot;), but others do not (the default customer should be &lt;em&gt;all&lt;/em&gt; customers).&lt;/p&gt;
&lt;p&gt;How does one handle the optionality of the latter case? &lt;/p&gt;
&lt;p&gt;Here is a contrived example that demonstrates the problem:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;  (d/q &#039;[:find ?p
         :in $ ?name
         :where [?p :product/name ?name]]
    db
    &quot;My Product&quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is fine if the user actually provides the name of a product to filter by, but if they don&#039;t, I&#039;d like to default to returning &lt;em&gt;all&lt;/em&gt; products. I could easily just create two separate queries, one where the product name is an input, and the other where it isn&#039;t, but there would then be a combinatorial explosion of queries to cover all input possibilities.&lt;/p&gt;
&lt;p&gt;Passing &lt;code&gt;nil&lt;/code&gt; in as an input results in an exception.&lt;/p&gt;
&lt;p&gt;Perhaps the best way to solve this is not within the query at all, and I should instead query for the lazy seq of all entities, and then just use Clojure&#039;s &lt;code&gt;filter&lt;/code&gt; to trim that list down?&lt;/p&gt;
</description>
<category>Client API</category>
<guid isPermaLink="true">https://ask.datomic.com/index.php/616/how-to-gracefully-handle-optional-query-inputs</guid>
<pubDate>Sun, 23 May 2021 17:01:29 +0000</pubDate>
</item>
</channel>
</rss>