3

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?

Y.H Wong
  • 7,151
  • 3
  • 33
  • 35

1 Answers1

4

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.

hakvroot
  • 326
  • 2
  • 6
  • Ah ok. So it seems that the ~ op comes from NumericalExpression, which you get from some magical implicit conversion from PrimitiveTypeMode after typing ~. The only reason you need it is because due to the magical nature of implicits, you never know for sure what any arithmetic/logical ops will resolve to. Using 'plus' or '~' ensures you get the right type. – Y.H Wong Dec 18 '10 at 14:33