Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slick compare table column with null

Tags:

scala

slick

Can someone please tell me how do we compare a table column against NULL using slick's lifted embedding.

What i want to achieve in mysql:

select * from Users where email = '<some_email_addr>' and ( removed = NULL OR removed <= 1 )

It gives me an errors at x.removed === null when i try:

val q = for {
    x <- Users
        if x.email === email && ( x.removed === null || x.removed <= 1 )
} yield x.removed

Thanks

like image 583
Sameerel Avatar asked Jul 16 '13 05:07

Sameerel


3 Answers

Try:

x.removed.isNull

I think that is what you are looking for

like image 58
cmbaxter Avatar answered Nov 19 '22 03:11

cmbaxter


As daaatz said and per http://slick.typesafe.com/doc/2.1.0/upgrade.html#isnull-and-isnotnull you should use isEmpty, but it only works on Option columns. A workaround is x.removed.?.isEmpty.

like image 29
Mar77i Avatar answered Nov 19 '22 03:11

Mar77i


Try

x.removed.isEmpty()

There are no nulls in scala ;-)

like image 40
daaatz Avatar answered Nov 19 '22 02:11

daaatz