Slick Embedded equivalent SQL case statement : Column Masking

328 views
Skip to first unread message

Colin

unread,
Jan 26, 2014, 11:52:18 PM1/26/14
to scala...@googlegroups.com
Hi,

I'm using lifted embedding, I was wondering if this is possible, I tried playing around with yield but with no success.

My case class looks something like this. case class Info(data: String, company:String, user:String)

The regular SQL that I would use is as follows.

select data, company,CASE WHEN user='randomuser' THEN 'New Company' ELSE company END as companyName from info

Ultimately, I want to mask certain columns if some conditions are true without having to have to get results and loop through it again.

Thanks.

Christopher Vogt

unread,
Jan 30, 2014, 4:13:00 AM1/30/14
to scala...@googlegroups.com
Hi Colin,

I have never used Column Masking, but isn't that a server-side feature?

In case you are just looking for a Slick-equivalent for the SQL case
statement, we actually support that, but it seems currently
undocumented. Here is an example from our tests:

https://github.com/slick/slick/blob/038f1784daa947fed0f8439ee87c5f2a1e62c67d/slick-testkit/src/main/scala/com/typesafe/slick/testkit/tests/MainTest.scala#L64

Does this help you?

Chris

Colin Nieuwenhuizen

unread,
Jan 30, 2014, 11:47:48 AM1/30/14
to scala...@googlegroups.com
Hi Chris,

I didn't really mean column masking as a feature but more of a use of that case statement, sorry for the confusion.

That said, what you have in those tests is exactly the functionality I was after, I tested it out and it works great, thanks!  

One quick question though, if you're yielding a list of tuples, would you have to apply them to case classes after your query since you're dealing with Column type's in the yield block?

Thanks again,
Colin



--

---
You received this message because you are subscribed to a topic in the Google Groups "Slick / ScalaQuery" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/scalaquery/NmMuoqsAoyg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to scalaquery+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scalaquery/52EA179C.5030702%40gmail.com.

Christopher Vogt

unread,
Jan 30, 2014, 5:37:10 PM1/30/14
to scala...@googlegroups.com
>One quick question though, if you're yielding a list of tuples, would
>you have to apply them to case classes after your query since you're
>dealing with Column type's in the yield block?

Yes. Either use

query.run.map(MyCaseClass.tupled)

For read-only, or use <> for a read-write mapping.

Chris
Reply all
Reply to author
Forward
0 new messages