Guide or directions on making custom Squeryl functions?

36 views
Skip to first unread message

Brian Maso

unread,
Jan 22, 2019, 8:22:08 PM1/22/19
to squ...@googlegroups.com
Hi,

I'm interested in making a couple customer Squeryl functions, specifically to match two multi-parameters SQL functions:

* if(test, true-val, false-val)
* pow(base, exponent)

There must be a few useful examples out there of how to create such things... but I'm not having a lot of luck finding them. I have found a few examples, but they seem to be targeting an older version of the Squeryl API. Anyone have any pointers?

--
Best regards,
Brian Maso
(949) 395-8551
Follow me: @bmaso
br...@blumenfeld-maso.com

Brian Maso

unread,
Jan 22, 2019, 9:33:33 PM1/22/19
to squ...@googlegroups.com
Answering my own question: Wow, making your own Squeryl functions is crazy-easy. I've been intimidated about this aspect of Squeryl for a long time for no good reason.

Simply create an instance of the FunctionNode class, and place it anywhere in a Squeryl query that an expression is called for. Here is an example of invoking a SQL native "sqrt()" function:

from(mytable)( r =>
  select(new FunctionNode("sqrt", Seq(t.someNumericField))))

Of course you might want to wrap the object creation up in a convenience method. But that's just DSL forging.

Brian Maso
Reply all
Reply to author
Forward
0 new messages