It is often necessary to create queries that varies depending on values known only at runtime.
The method inhibitWhen(b: Boolean) available on org.squeryl.Queryable[A]
is meant to be called in a from clause, it will turn a Table[A] or (sub) Query[A]
into a Queryable[Option[A]] and remove the queryable from the query
and all expression referencing this queryable.
Example :
Notice the Option[] in the result type of the query, and how the Author
table disappears from the generated SQL base on the input of inhibitWhen :
The following method builds a query with a dynamically varying where clause, the .? function on the optional parameters has the effect of removing the enclosing condition when the argument is None.
Observe how following calls affect the generated SQL :
The same method using inhibitWhen would be :