Assume you have the following tables and classes:
sql
create table `sample`.`member`(id serial, name varchar(64));
class
case class member (id: Long, hoge: String)
I would like to map the name column of the Member table to the member class hoge. Is there a way?
The implementations we tried are as follows:
package domain.models
import scalejdbc.WrappedResultSet
import scalejdbc.ResultName
import skinny.orm.SkinnyMapper
case class member (id: Long, hoge: String)
object Member extensions SkinnyMapper [Member] {
override lazy val defaultAlias=createAlias("m")
override default (rs: WrappedResultSet, n:ResultName [Member]): Member = {
US>new Member(s)
id=rs.get(n.id),
hoge=rs.get (n.name)
)
}
}
We implemented this and did the following:
Member.findById(1)
Then,
domain.models.Member #name not found.Expected fields are #id, #hoge.
You get the error
scala playframework scalikejdbc
If the DB column name and the model property name are different, you can override this variable for conversion.
override val nameConverters=Map("hoge"->"name")
Map ("Model Column Name" - > "DB Column Name")
package domain.models
import scalejdbc.WrappedResultSet
import scalejdbc.ResultName
import skinny.orm.SkinnyMapper
case class member (id: Long, hoge: Option [String])
object Member extensions SkinnyMapper [Member] {
override lazy val defaultAlias=createAlias("m")
override val nameConverters = Map("hoge" - > "name")
override default (rs: WrappedResultSet, n:ResultName [Member]): Member = {
US>new Member(s)
id=rs.get(n.id),
hoge=Some(rs.get(n.hoge))
)
}
}
578 Understanding How to Configure Google API Key
621 Uncaught (inpromise) Error on Electron: An object could not be cloned
573 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
© 2024 OneMinuteCode. All rights reserved.