Check if sql query is empty

I want to use dynamic query building specifically if my other query is non-empty. My code block should determine is a specific value was passed as input (location data). If it wasn't then the query should be run as normal. If it has then I should adjust query where clause using the helper function. Having problems with when no input is provided because I can't compare my variable to sql.empty() or sql'' template. Here is the snippet:
if(locationSqlClause != sql.empty()){
query = withLocations(query, locationSqlClause);
}
if(locationSqlClause != sql.empty()){
query = withLocations(query, locationSqlClause);
}
1 Reply
TKR👑
TKR👑OP•9mo ago
Solved by not assigning locationSqlClause unless necessary and checking using if != undefined... linter cries a bit but works
Want results from more Discord servers?
Add your server