Question

I am a Scalatra beginner and I have the following route:

  get("/todos") {
    contentType = formats("json")

    val userid : Int = params.getOrElse("userid", halt(400)).toInt
    val limit : Int = params.getOrElse("limit", "0").toInt
    val offset : Int = params.getOrElse("offset", "0").toInt

    if(limit != 0 && offset != 0) 
        from(TodoDb.todos)(todo => where(todo => todo.userid == userid) select(todo)).toList
    else {
        from(TodoDb.todos)(todo => where(todo => todo.userid == userid) select(todo) orderBy(todo.modified)).page(offset, limit).toList
    }
  }

I can't compile it, I got the following error messages:

[info] Compiling 1 Scala source to /home/coelho/www/p.zomg.hu/gfmwa-todo-app/target/scala-2.10/classes...
[error] /home/coelho/www/app/src/main/scala/hu/gfmwa/todoapp/TodoScalatraServlet.scala:25: missing parameter type
[error]         from(TodoDb.todos)(todo => where(todo => todo.userid == userid) select(todo)).toList
[error]                                          ^
[error] /home/coelho/www/app/src/main/scala/hu/gfmwa/todoapp/TodoScalatraServlet.scala:27: missing parameter type
[error]         from(TodoDb.todos)(todo => where(todo => todo.userid == userid) select(todo) orderBy(todo.modified)).page(offset, limit).toList
[error]                                          ^
[error] two errors found
[error] (compile:compile) Compilation failed

I learn from here: http://squeryl.org/selects.html and here: http://squeryl.org/pagination.html

I can't see parameter type information on these pages, I can't figure out, what can be the problem. What I am doing wrong?

Was it helpful?

Solution

where doesn't expect a function inside ( todo=> ), but rather just a boolean thing. So, to make your code work, write something like from(TodoDb.todos)(todo => where(todo.userid === userid) select.

BTW, I suggest to be immediately cautious when seeing a code fragment like (todo => where (todo => (double "todo" definition).

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