mapping - scala slick 2.0.2 cannot automatic map to custom class -


i'm starting play slick , can't figure out how results of query mapped on custom case class. here's code:

package main.scala.model.tree  import scala.slick.driver.h2driver.simple._  case class slicknode(id : long, parentid : long, statestring : string)      extends abstractnode{}  object slicknode {     val nodes = tablequery[slicknodes]     def findbyid(x : long) : slicknode = nodes.filter(_.id == x).first     def findbyparentid(x : long) : iterable[slicknode] = nodes.filter(_.parentid == x).list  }  class slicknodes(tag: tag) extends table[(long, long, string)](tag, "nodes") {     def id = column[long]("node_id", o.primarykey, o.autoinc)     def parentid = column[long]("parent")     def statestring = column[string]("state")     def * = (id, parentid, statestring) <> ((slicknode.apply _).tupled , slicknode.unapply) } 

what expected automatic conversion (long, long, string) slicknode stated in * definition. missing something? thank in advance. kind regards

********* edit ********* think problem deeper in code. when try compile error:

[error] no matching shape found. [error] slick not know how map given types. [error] possible causes: t in table[t] not match * projection. or use unsupported type in query (e.g. scala list). [error]   required level: scala.slick.lifted.shapelevel.flat [error]      source type: scala.slick.lifted.mappedprojection[main.scala.model.tree.slicknode,(long, long, string)] [error]    unpacked type: (long, long, string) [error]      packed type: [error]   def * = (id, parentid, statestring) <> ((slicknode.apply _).tupled , slicknode.unapply) [error]                                       ^ 

the problem extending table of triple, not table of slicknoderow:

class abstractnode  case class slicknoderow(id : long, parentid : long, statestring : string) extends abstractnode  object slicknode {   val nodes = tablequery[slicknodes]   def findbyid(x : long)(implicit s: session): option[slicknodes#tableelementtype] = nodes.filter(_.id === x).firstoption   def findbyparentid(x : long) : iterable[slicknoderow] = nodes.filter(_.parentid == x).list }  class slicknodes(tag: tag) extends table[slicknoderow](tag, "nodes") {                                              * here      def id = column[long]("node_id", o.primarykey, o.autoinc)   def parentid = column[long]("parent")   def statestring = column[string]("state")   def * = (id, parentid, statestring) <> ((slicknoderow.apply _).tupled , slicknoderow.unapply) } 

and projections function doesn't know how map triple slicknoderow case class. if want return triple code should this:

class suppliers(tag: tag) extends table[(int, string, string)](tag, "suppliers") {   def id = column[int]("sup_id", o.primarykey)   def name = column[string]("sup_name")   def street = column[string]("street")   def * = (id, name, street) } val suppliers = tablequery[suppliers] 

as shown here, projection doesn't return case class, triple instead. write projection method in way return slicknoderow triple, i'm not sure though.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -