score:0

Accepted answer

well, i wouldn't involve constants in select but use them only when managing results loaded from db.

try it like:

 def cannotunpack(db: database) {
    db.withsession {
      val data = (for {
        rw1 <- tableone
        rw2 <- tabletwo if rw1.cl1 === rw2.cl1 && rw1.cl2 === rw2.cl2 && rw1.cl1 === "0"
      } yield (uuid, rw1.cl3)
    }
  }

after that get your data ready for what you need:

for (
  (uuid, rw1_cl3) <- data.list
) yield (uuid, rw1_cl3, some("constant"), 6, new timestamp(system.currenttimemillis()))

i usually use an output case class when preparing final data, for instance:

case class export(uuid: string, rw1: string, constant: option[string], six: string, now: timestamp)

for (
      (uuid, rw1_cl3) <- data.list
    ) yield export(
             uuid, 
             rw1_cl3, 
             some("constant"),  
             6, 
             new timestamp(system.currenttimemillis()))

score:1

the short answer: it works, if you write some("someconstant") : option[string].

the long answer: if you supply a constant as part of your slick query, slick has to put the value into the sql query and later read it back from the results. this preserves composability, i.e. allows you to use the slick query as a component in another slick query. in order to encode the value into the sql query, the method you are calling (in case of a comprehension: map or flatmap) needs to find an implicit value of type typemapper[t] where t is the type of the value. slick does define a typermapper[option[string]] but the problem is that it does not apply in your case, because some("someconstant") is of type some[string] and there is no typemapper[some[string]] defined in slick (and typemapper[t] is invariant in t). by explicitly supplying :option[string], you loosen the type information, so a matching typemapper can be found.

we will think about if we can add support for constants of type some into slick. i added a ticket (https://www.assembla.com/spaces/typesafe-slick/tickets/268) and will bring it up in our next team meeting.


Related Query

More Query from same tag