2

I'm fairly new to Scala and currently using an ORM called Squeryl against our MySQL database.

What I'm trying to do is looking up plural records that fall within a time range. For example, in plain SQL, I think it would be something like:

    SELECT * FROM records WHERE updated_at >= ? AND updated_at < ? 

However, my Scala code to achieve similar behavior as below, gives me an error saying "java.util.Date does not take parameters" at the opening bracket in "from(records)"

    def getRecordsBetween(from:java.util.Date, til:java.util.Date):List[Record]
      transaction {
        from(records)(record =>
          where(
            record.updatedAt gte from and
            record.updatedAt lt til
          )
          select(record)
        ).toList
      }
    }

(where val records = tableRecord

What am I doing wrong here? Thanks a lot in advance.

Hongweng
  • 129
  • 1
  • 8
  • Just a guess, but did you try to surround the comparisons with parentheses, i.e., ``where((record.updatedAt gte from) and (record.updatedAt lt til))``? – Malte Schwerhoff Jul 15 '12 at 12:56

1 Answers1

3

Method parameters and methods are in the same namespace in Scala, so your from method parameter is "shadowing" the from method on the PrimitiveTypeMode (or CustomTypeMode) object that you brought into scope with a line like the following:

import org.squeryl.PrimitiveTypeMode._

Just change the parameter name to fromDate or start or whatever and you should be fine.

Travis Brown
  • 138,631
  • 12
  • 375
  • 680
  • Thank you for pointing this out! So it was rather an issue of my var/val naming than Squeryl's. Not sure why I didn't think of that... *facepalm* – Hongweng Jul 18 '12 at 04:59