slick - How can I convert Rep[Option[Instant]] to Rep[Option[String]] in scala -
i working scala play 2, slick , postgresql database. 1 of function
def getallcustomerswithaccount: future[seq[customerdetail]] = { val joinexception = { (customer, account) <- table join accounttable on (_.id === _.id) } yield (customer.id, account.name, account.phone, account.email, customer.status, customer.balance, customer.payable, customer.created, customer.updated) val result = db.run(joinexception.result) result.map(row => row.map(x => customerdetail(x._1, x._2, x._3, x._4, x._5, x._6, x._7, x._8, x._9))) }
this code not working. problem created , updated property of customer. customer.created , customer.updated rep[option[instant]] date time. if escape 2 column (customer.created , customer.updated) it's ok.
def getallcustomerswithaccount: future[seq[customerdetail]] = { val joinexception = { (customer, account) <- table join accounttable on (_.id === _.id) } yield (customer.id, account.name, account.phone, account.email, customer.status, customer.balance, customer.payable) val result = db.run(joinexception.result) result.map(row => row.map(x => customerdetail(x._1, x._2, x._3, x._4, x._5, x._6, x._7))) }
this code working fine. want convert rep[option[instant]] rep[option[string]]. how can this?
slick requires mapping
custom types
known jdbc types
. provide implicit mapping slick datetime
timestamp
or instant
timestamp
in case. helps slick
to understand custom types
in terms of native database supported types
.
implicit def jodatimemapping: basecolumntype[datetime] = mappedcolumntype.base[datetime, timestamp]( datetime => new timestamp(datetime.getmillis), timestamp => new datetime(timestamp.gettime))
above implicit
helps slick
convert datetime
timestamp
, vice versa.
in case of instant type
assuming instant
wrapper around datetime
case class instant(time: datetime) implicit def instantmapping: basecolumntype[instant] = mappedcolumntype.base[instant, timestamp]( instant => new timestamp(instant.time.getmillis), timestamp => instant(new datetime(timestamp.gettime)))
slick implicit mapping java.time.instant
import java.sql.timestamp implicit def instantmapping: basecolumntype[instant] = mappedcolumntype.base[instant, timestamp]( instant => new timestamp(instant.toepochmilli), timestamp => instant.ofepochmilli(timestamp.gettime))
Comments
Post a Comment