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 8878029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:36:50+00:00 2026-06-14T19:36:50+00:00

I have the need to perform some queries that may depend on external supplied

  • 0

I have the need to perform some queries that may depend on external supplied parameters via a REST interface. For instance a client may require an URL of the form

some/entities?foo=12&bar=17

The parameters, say foo, bar and quux are all optional. So I start from designing some queries with Squeryl, like

object Entity {
  def byFoo(id: Long) = from(DB.entities)(e =>
    where(e.foo === id)
    select(e)
  )
  // more criteria
}

But of course I want to avoid the combinatorial explosion that arises, so I only design three queries, which in turn may take their data from another query:

object Entity {
  def byFoo(id: Long, source: Query[Entity] = DB.entites) = from(source)(e =>
    where(e.foo === id)
    select(e)
  )
  def byBar(id: Long, source: Query[Entity] = DB.entites) = from(source)(e =>
    where(e.bar === id)
    select(e)
  )
  // more criteria
}

Now I can combine them and run a query like

val result = Entity.byFoo(12,
  source = Entity.byBar(17)
)

The only problem I have with this approach is that behind the scenes Squeryl is going to generate a subquery, which may be inefficient. With a more typical query builder, I would be able to combine the queries and get the equivalent of the following:

from(DB.entities)(e =>
  where(
    e.foo === 12 and
    e.bar === 17
  )
  select(e)
)

Is there a different way to dynamically combine queries in Squeryl that will lead to this more efficient form?

  • 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-14T19:36:51+00:00Added an answer on June 14, 2026 at 7:36 pm

    The first thing I think you should look into is inhibitWhen, which you can find in the documentation. The gist of it is that you model your query like:

    var foo: Option[Int] = None
    var bar: Option[Int] = None
    
    from(DB.entities)(e =>
      where(
        e.foo === foo.? and
        e.bar === bar.?)
      select(e))
    

    The ? operator in the first expression is equivalent to (e.foo === foo).inhibitWhen(foo == None)

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

Sidebar

Related Questions

I have a class that I need to perform some actions on but I
I have a lotus view that stores a number. I need to perform some
I have a task I need to perform, do_stuff(opts) , that will take ~1s
I have a few sprocs that execute some number of more complex queries and
I have a method myButtonAction which performs some heavy calculations, which I need to
I have a need to perform search and replace operations on large blocks of
I have the need to perform algorithms on various primitive types; the algorithm is
I need to perform an action after a session times out. However I have
I have a pretty simple SQL I need to perform. I have a ProcessUser
I need to perform action, when my activity is fully loaded? Does Android have

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.