Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the SQueryL tilde operator do?

Tags:

scala

squeryl

I was reading the SQueryL documentation on updating and I saw:

update(songs)(s =>
  where(s.title === "Watermelon Man")
  set(s.title := "The Watermelon Man",
      s.year  := s.year.~ + 1)
)

I had a hard time finding the ~ method from the SQueryL source code and the linked documentation obviously doesn't tell me what it does either. Does anyone care to explain?

like image 772
Y.H Wong Avatar asked Dec 02 '25 05:12

Y.H Wong


1 Answers

I recall reading about the tilde operator not too long ago on the Schema Definition Page. It is about disambiguating between a primitive and a custom type, although (as I am just beginning to learn Scala) it still sounds a bit vague to me ;). To quote a little piece

...

important : in PrimitiveTypes mode there can be ambiguities between numeric operators

When using org.squeryl.PrimitiveTypeMode, the compiler will treat an expression like the one in the next example as a Boolean. The .~ function is needed to tell the compiler that the left side is a node of TypedExpressionNode[Int] which will cause the whole expression to be a LogicalBoolean which is what the where clause takes :

...

Hope that helps.

like image 99
hakvroot Avatar answered Dec 03 '25 18:12

hakvroot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!