1
votes

When migrating to play 2.4 I noticed the following:

1/apply is deprecated on SqlQuery - ok - I looked at the provided implementation :

def go(c: Option[Cursor], s: Stream[Row]): Stream[Row] = c match {
      case Some(cursor) => go(cursor.next, s :+ cursor.row)
      case _ => s
    }

Isn't that appending each element to a Stream which time is proportional to the size of stream? eg doesn't that end up being n2? The previous implementation used cons I think...

2/SqlQuery("qry") used to have a way to not parse the query - That seems to have been removed

I have a use case with a query executed often (like 1000qps) and that I cannot cache once : it looks like select X,Y,Y from dbname.db - So no bindable statement for database name. For a large query it turns out the statement parser is somewhat slow - Is there a way to explicitly say: I don't need that query parsed?

3/ResultSetParser has gone totally private - I had a util function that provided:

def vector[A](p: RowParser[A]): ResultSetParser[Vector[A]] ...

because I prefer Vector - I used that with SQL("...").as Any suggestion as to how to replace? withResult maybe?

1
You can find a migration doc online: playframework.com/documentation/2.4.x/Anorm - cchantep
please do share your findings on the migration - i think a lot of people will be interested - wwkudu

1 Answers

0
votes

1. The current implementation of .apply is there only for backward compatibility, as deprecated. If you want to do streaming, you can have a look at the Streaming support: .withResult, .foldWhile

2. Constructing directly the underlying query types (SqlQuery) is no longer allowed, as it would bypass some checks done while using the public constructor SQL(...) (or SQL interpolation SQL"..."). Nothing prevent from keeping a query init'ed in this way to re-use it with different parameters.

val baseQuery = SQL("SELECT * FROM Test WHERE id = {id}")
val query1 = baseQuery.on("id" -> "foo")
val query2 = baseQuery.on("id" -> "bar")

3. As said on the issue tracker, the ResultSetParser was not designed to be a general purpose type, but for internal use in Anorm implementation. Unsealing it would have a maintenance impact.

You can either get a Vector from a List (.* or .+ parsers), or use Streaming support to build the vector by yourself without intermediary list.