You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Many databases nowadays have functionality to test whether some query returns any results, specifically using EXISTS() . I now often resort to a raw query to make use of this, but it would be great to have a dedicated function to compose EXISTS parts of a query. For instance
db.Select("EXISTS(SELECT * FROM posts WHERE user_id = 5) AS userHasPosts").Find(&users)
The key aim here is not to have to resort to writing raw SQL in strings, because this makes it much harder and error prone to dynamically construct queries that serve as argument to the EXISTS() function, and makes the query much more vulnerable to SQL injections.
I am not familiar at all with writing SQL builders, so I have no clue if this would be hard to implement, or whether there were already good reasons (I couldn't find any) why this hadn't been implemented before, but I would love to hear peoples thoughts on this.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Many databases nowadays have functionality to test whether some query returns any results, specifically using
EXISTS()
. I now often resort to a raw query to make use of this, but it would be great to have a dedicated function to compose EXISTS parts of a query. For instancecould very roughly become something like
Another example, to perform a WHERE EXISTS:
one could write
The key aim here is not to have to resort to writing raw SQL in strings, because this makes it much harder and error prone to dynamically construct queries that serve as argument to the
EXISTS()
function, and makes the query much more vulnerable to SQL injections.I am not familiar at all with writing SQL builders, so I have no clue if this would be hard to implement, or whether there were already good reasons (I couldn't find any) why this hadn't been implemented before, but I would love to hear peoples thoughts on this.
Beta Was this translation helpful? Give feedback.
All reactions