Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request - Support Dynamic Where Clauses for Query #38

Open
vitulrana opened this issue Jul 1, 2020 · 1 comment
Open

Feature Request - Support Dynamic Where Clauses for Query #38

vitulrana opened this issue Jul 1, 2020 · 1 comment
Labels
codegen deals with generated code design discussion required Issue that needs discussion with maintainers for deciding on approach enhancement New feature or request hacktoberfest

Comments

@vitulrana
Copy link
Contributor

vitulrana commented Jul 1, 2020

Hi Team,

We need a Feature in NORM where we don't have to write multiple queries for multiple cases/filters which we want rather NORM should be able to take decision on its own that if Given Param is NULL/Empty is some case it should not add its Column in WHERE clause.

For Example -

We want to have a Users API where we want to support filtering by name, address_line, city, state and zip_code.

Current Solution -

We have to write multiple queries for each case like

SELECT * FROM users WHERE name = 'XXXX';
SELECT * FROM users WHERE address_line = 'XXXX';
....
....
SELECT * FROM users WHERE zip_code = 'XXXX';

And then if we need combination we will need combinations also, then we would few more queries like

SELECT * FROM users WHERE zip_code = 'XXXX'; AND city = 'XXXX'; and so on.......

Expected Solution -

NORM should generate query on the fly according to Parameters given to it like below code somewhat -

if (!addressLine.isNullOrEmpty()) then
query = query + WHERE a.address_line = addressLine

if (!city.isNullOrEmpty()) then
query = query + WHERE a.city = city

if (!state.isNullOrEmpty()) then
query = query + WHERE a.state = state

if (!zip_code.isNullOrEmpty()) then
query = query + WHERE a.zip_code = zip_code
@kdabir
Copy link
Member

kdabir commented Jul 3, 2020

This is one of the very useful feature, however we need to carefully design it since we need to ideally parse the query to be able to produce syntactically correct dynamic query. Just imagine cases like Group By,Order By present at the end of static query written in the file. We will probably create a simple DSL for dynamic queries. Stay tuned.

@ashwini-desai ashwini-desai added the codegen deals with generated code label Jul 6, 2020
@ashwini-desai ashwini-desai added enhancement New feature or request design discussion required Issue that needs discussion with maintainers for deciding on approach hacktoberfest labels Sep 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
codegen deals with generated code design discussion required Issue that needs discussion with maintainers for deciding on approach enhancement New feature or request hacktoberfest
Projects
None yet
Development

No branches or pull requests

3 participants