sql - How to create a variable length RowParser in Scala for Anorm? -
a typical parser in anorm looks bit this:
val idseqparser: rowparser[idandsequence] = { long("id") ~ int("sequence") map { case id ~ sequence => idandsequence(id, sequence) } }
assuming of course had case class so:
case class idandsequence(id: long, sequence: int = 0)
all handy-dandy when know front if want run ad-hoc queries (raw sql) write @ run time? (hint: on fly reporting engine)
how 1 tackle problem?
can create series of generic parsers or various numbers of fields (which see scala had resort when processing tuples on forms meaning can go 22 elements in form , unsure heck after that...)
you can assume "everything string" purpose of reporting option[string]
should cut it.
can parser created on fly however? if doing like?
is more elegant way address "problem"?
edit (to clarify i'm after)
as "ask" using aliases
select f1 'a', f2 'b', f3 'c' sometable
then collect pre-written parser
val idseqparser: rowparser[idandsequence] = { get[option[string]]("a") ~ get[option[string]]("b") ~ get[option[string]]("c") map { case ~ b ~ c => genericcase(a, b, c) } }
however means need de alias columns actual report output. suggestion of sqlparser.flatten
puts me ahead there has 22 (there's "literal" kludge!) columns.
as i've written reports greater 22 columns in times past -- inputs spreadsheets further manual dat mining -- escape limit if possible. hard tell client can't have urgent 27 column report 5 days 21 column 1 can have in 5 minutes...
going try experiment today see if can't find own workable solution.