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.

Add exists() method on Query to check assert the existence of a query

See original GitHub issue

Suggested Enhancement: Adding an exists() method on Query would allow to efficiently check the existence of a row or group of rows. Would be the SQL equivalent of SELECT EXISTS(SELECT 1 FROM table WHERE ...)

Exemple: FooTable.select { FooTable.id eq 5 }.exists() would be converted to: SELECT EXISTS(SELECT 1 FROM FooTable WHERE id = 5)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
damienmiheevcommented, Dec 29, 2021

It looks quite complex to use. Why don’t to add something like: val result: Boolean = FooTable.exists { FooTable.id eq 5 }

For example

fun <T: FieldSet> T.exists(where: SqlExpressionBuilder.() -> Op<Boolean>): Boolean {
    val existsOp = exists(this.select(where))
    val result = Table.Dual.slice(existsOp).selectAll().first()
    return result[existsOp]
}
2reactions
Tapaccommented, Aug 23, 2021

Yes, the “FROM” part will be skiped for PSQL for Table.Dual.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The best way to write a Spring Data Exists Query
There are better ways to write a Spring Data Exists Query. Checking existence with an existsBy query method. Spring Data offers an existsBy ......
Read more >
Django check for any exists for a query - python - Stack Overflow
Django provides a method called exists() to check if results exists for our query. exists() method return 'True' or 'False' Class Company(models.
Read more >
The Exists Query in Spring Data - Baeldung
The existsById query is the easiest, but least flexible way of checking for an object's existence. 4. Using a Derived Query Method.
Read more >
Introduction to Cypress
Important! This is the single most important guide for understanding how to test with Cypress. Read it. Understand it. Ask questions about it...
Read more >
HTTP Tests - Laravel - The PHP Framework For Web Artisans
The get method makes a GET request into the application, while the assertStatus ... that you did not make assertions against exist on...
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