Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top