question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`WHERE IN (...)` support

See original GitHub issue

From the docs:

Multiple objects passed to .where are joined with or.

sq.from`person`.where({ name: 'Rob' }, { name: 'Bob' }).query

{ text: 'select * from person where (name = $1 or name = $2)',
  args: ['Rob', 'Bob'] }

Any reason we couldn’t join the objects with IN (?, ?) notation?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

4reactions
eejdoowadcommented, Nov 2, 2018

Yep, I’m definitely going with 2. The current plan is to provide an expression builder.

I’m currently debating whether to provide a fluent interface or an expression tree interface.

// option 1: fluent interface
// pros: reads like SQL
// cons: confusing operator precedence, more difficult implementation
const condition =
  e('book.genre').in(['Fiction', 'History', 'Fantasy'])
  .and(e('book.publish_year').lt(1980))

// option 2: expression tree
// pros: explicit operator ordering, simpler implementation, easier typing
// cons: not like SQL
const condition = e.and(
  e.in('book.genre', ['Fiction', 'History', 'Fantasy']),
  e.lt('book.publish_year', 1980)
)

// both would be used like follows:
sq.from('book').where(condition).return('title', 'id').query
{ text: 'select title, id from book where (book.genre in ($1, $2, $3) and book.publish_year < $4',
  args: ['Fiction', 'History', 'Fantasy', 1980] }

I’m probably going with 2.

1reaction
eejdoowadcommented, Dec 21, 2018

A little bit behind schedule, and with MANY breaking API changes, but I ended up implementing a much more ambitious proposal: a functional, strongly typed expression builder.

See https://sqorn.org/docs/expressions.html.

// All the queries below produce:
// 'select * from book where id in ($1, $2, $3)'

// pass multiple arguments to .sql to build a values list
sq.sql`select * from book where id in`.sql(1, 2, 3)

// object form detects array and builds in
sq.from`book`.where({ id: [1, 2, 3] })

// e.in operation accepts two arguments
sq.from`book`.where(e.in(e`id`, [1, 2, 3]))

// operations can be curried
sq.from`book`.where(e.in`id`([1, 2, 3]))

// operations can be chained
sq.from`book`.where(e`id`.in([1, 2, 3]))

Switch to package ‘@sqorn/pg’ v0.0.45. See the updated tutorial setup: https://sqorn.org/docs/setup.html

Read more comments on GitHub >

github_iconTop Results From Across the Web

Google Help
Your account. Can't access your account? Recent transactions with Google · Help Communities. Learn more about. Google's Product Experts Program · Status dashboard....
Read more >
Access SQL: WHERE clause
In a SQL statement, the WHERE clause specifies criteria that field values must meet for the records that contain the values to be...
Read more >
Official Apple Support
Get up to date information about your Apple products in one place including repairs, tech support cases, and much more. Sign in to...
Read more >
How to Contact Google Support for Help With Any Issue
Google has a customer service number you can call, though it's largely automated. Google Support tutorials and Community help forums provide ...
Read more >
Contact Support
Contact Support. Log in to your Shopify account to get support for a store. Log in. I don't have an account. Troubleshooting. Reset...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found