score:0
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.
Source: stackoverflow.com
Related Query
- Slick 1.0.0 | Return Expression From For Comprehension
- How do I return a String from a for comprehension in Scala?
- A better syntax for recovery from a for comprehension
- why can't I extract a tuple from Either projection inside for comprehension using pattern matching?
- Scala return a value from a for cycle
- Sorting Slick query results in a for expression
- Extract Options from potentially null JSON values using for expression
- Rewrite a nested flatmap expression with an if and else clause to a for comprehension
- Return a specific type from for yield in Scala
- How to avoid return statement and escape from for loop?
- Conditionally running Slick statements in a for comprehension
- Slick "===" compiling only in for comprehension
- Filtering and mixing monads in Slick for comprehension and Cats
- Why does implement abstract method using val and call from superclass in val expression return NullPointerException
- How to handle futures that return options in a for comprehension
- Scala for comprehension for Slick Query
- scala - return different value for comprehension for matching patterns
- How to successfully combine slick read action and then slick write action in for comprehension
- How to return 2 decimal points for BigDecimal in JSON response from Scala/Play Framework
- Return elements from array, except for repeating
- Return from nested condition, for loop, try/catch block in Scala
- Early return from a for loop in Scala
- For Comprehension Return type
- is there an equivalent of flattening return values if I use for comprehension within for comprehension
- Don't return same type from filter for efficiency
- Disconnect from Slick JNDI connection in Play for Scala
- How to return Future of Either[Throwable,Int] from a Scala Slick Query output
- Future and Option in for comprehension in slick
- Error on return a Future[Boolean] from a for in Scala
- read autoincrement Id without running db.run and without for comprehension in Slick in single transaction
More Query from same tag
- Getting subtype from nested type
- how to load first x bytes from URL with Java / Scala?
- (SBT) How to disable default resolver and only use the company internal resolver?
- Akka Flow hangs when making http requests via connection pool
- Spark - How to do rollup on a defined heirarchy where parent element not present in dataset
- Coercing the value of a shapeless record
- Adding extra trait to object using scala macro annotation
- How to Split the row by nth delimiter in Spark Scala
- Finding average of values against key using RDD in Spark
- date_format doesn't handle timestamp with `00:00:00`
- Flink - how to aggregate and query a rich sink functions state across multiple task slots
- How was it possible to make existing Java classes subclasses of AnyRef in Scala?
- Scala - Co/Contra-Variance as applied to implicit parameter selection
- Approx quantile on a array of doubles - Spark dataframe
- Play JSON Reads/Writes with single-parameter case classes
- computing base class parameters from derived class
- Scala future sequence and timeout handling
- how to read all elements of json array in scala
- Apache Spark: map vs mapPartitions?
- Java/Scala best way to get difference between two DateTime objects as List of DateTime
- Scala variable argument list with call-by-name possible?
- How to calculate unique session id per user per minute in a click stream dataset using Spark-SQL?
- Concurrently running Scala FS2 Streams
- Play Framework float in Template with comma
- Skipping to the beginning of a for loop in a Scala program
- Can I Determine the Set of First Chars Matched by Regex Pattern?
- Scala constructor
- Find a type in REPL?
- Why += doesn't work with Lists?
- How to filter a row if the value contains in list in scala spark?