Like clause not working with int column in slick

489 views Asked by At

Slick doesn't seem to support like clauses on int columns. The following code where Status.code is of int type doesn't seem to work. Would there be a workaround for this?

val query = for {
  s <- Status if s.code like "1%"
} yield (s)
1

There are 1 answers

0
Biswanath On BEST ANSWER

Can you post your Status class definitation .If code is type column[Int] your code should be giving error as like works on column[string].

The below snippet works for doing a like on integer field.

class Coffees(tag: Tag) extends Table[(String, Int)](tag, "COFFEES") {
    def name = column[String]("NAME")
    def status = column[Int]("STATUS")
    def * = (name,status) 
}

This is data insert and querying part

coffees ++= Seq(
        ("Colombian",         101),
        ("French_Roast",       49),
        ("Espresso",          150),
        ("Colombian_Decaf",   101),
        ("French_Roast_Decaf", 49)
      ) 

for( coffee <- coffees if coffee.status.asColumnOf[String] like "1%" ) 
    println(coffee)