Parsing different queries with same parser anorm

40 Views Asked by At

I was trying to parse some different SQL queries using one anorm parser. Some of the queries will return a,b,c as their result. Eventually, one of the query will return a,b,c,d,e.

The result is tightly coupled to a return object called Obj with definition like:

case class Obj(a:Int,b:String,c:String,d:Option[String],e:Option[Double]

The parsing is done using :

val parser = Macro.namedParser[Obj](ColumnNaming.SnakeCase)
SQL("""select a,b,c .....further query""").on("a"->a).as(parser *)
SQL("""select a,b,c,d,e .... further query""").on("a"->a).as(parser *)

Can I get the parser to avoid looking up for d,e in first case.

I want to make both the queries work and the result to be parsed under same object. As its a legacy codebase and the object is used at multiple places for parsing.. I would prefer to avoid to map all other queries to some other object and then copy the values there with None in d,e fields.

0

There are 0 best solutions below