Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8957119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:54:50+00:00 2026-06-15T14:54:50+00:00

How does Slick translate code such as: val q2 = for { c <-

  • 0

How does Slick translate code such as:

val q2 = for {
  c <- Coffees if c.price < 9.0
  s <- Suppliers if s.id === c.supID
} yield (c.name, s.name)
for(t <- q2) println("  " + t._1 + " supplied by " + t._2)

Into JDBC?

Does it use Scala Virtualized? Does it use some other method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T14:54:52+00:00Added an answer on June 15, 2026 at 2:54 pm

    Slick’s stable API achieves this via what it calls lifted embedding. Your example is clearly using the stable API (as you use === for equality and not ==).

    The beauty of Slick (and in turn Scala) is that – this much is achieved without using macros or Scala-Virtualized. (Side Note: Slick’s experimental API does use macros – and this will allow you to use == instead of === or is)

    The translation to SQL is achieved using:

    1. Scala’s for comprehension syntax, which is translated to method calls.
      Tables defined in Slick are Monads – they have the magic foreach, map,
      flatMap, and
      filter methods which allow them to be expressed in for ‘loops’ while Scala
      translates them to method calls (as correctly illustrated in the code
      provided by the other answer by @emil-ivanov).

      As with regular Scala collections, the for is syntactic sugar for nested
      method calls to flatMap/map and filter; unlike regular collections,
      the Slick Table objects’ versions of map and filter return representations
      of a query, building it along with every filter condition (if) or join
      (as in s <- Suppliers if s.id is c.supID)

      So the type of q2 is not your usual collection (as a for comprehension in Scala
      is typically used to return), but rather a representation of a query.
      (Just as the Scala Option Monad also works with for comprehensions despite
      not being a ‘collection’ (in the way that List or Map is))

      You can see the underlying query with q2.selectStatement.

    2. Scala’s implicit lifting – c.price is not an Int but rather a representation of
      a column value – so the expression c.price < 9.0 becomes c.price.<(Const(9.0))
      (an Int is lifted to the desired type), and < is a just a method of the
      class that represents c.price, a Column. The < method
      does not do what < usually does (in the case of plain Ints) – it simply returns
      a representation of the SQL AST corresponding to price < 9 that becomes part of
      the SQL that is generated and sent off to JDBC to execute.

    There’s a whole lot else going on, in terms of details, but I think the query monad and the implicit lifting are the chief ingredients.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know if there is a way to generate different code in the
Does anyone have a translate function for x/y positions after rotation in javascript? for
Does anyone know of a free tool, similar to what is built into Visual
Does the following psuedo code accomplish my goal of cleaning up after myself when
Does anyone have a slick way of adding filler dots to a table of
I'm creating an app using the very slick KnockoutJS library, but I've run into
How does Slick handle a query that returns multiple result sets? For example, if
I assume it doesn't actually hash the file contents, does it stick all of
Does Scala have a version of Rubys' each_slice from the Array class?
Does COUNT(*) have any significant impact for MySQL performance if query already has GROUP

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.