Skip to content

can you add function for SELECT sql query #55

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

Closed
devorel opened this issue Oct 11, 2020 · 1 comment
Closed

can you add function for SELECT sql query #55

devorel opened this issue Oct 11, 2020 · 1 comment
Labels

Comments

@devorel
Copy link

devorel commented Oct 11, 2020

if (Object.keys(values).length > 1 && sql.toLowerCase().indexOf('select ') > -1 && (query.split(' ? ').length - 1) == 1) {
                sql = sql.replace('?', Object.keys(values).map((i) => {
                    return `${i}='${values[i]}'`;
                }).join(' AND '));
                values = 0;
            }

when i put some values for SELECT sql query, i get error !
so this add "and " between the parameters.
1)If SELECT sql query
2)If there are over 2 values (Because one works great)
3)If just one ? symbol (support in full query)

example

SELECT * FROM `customers` WHERE ?,{id:12345} =SELECT * FROM `customers` WHERE id='12345' //WORK

SELECT * FROM `customers` WHERE ?,{id:12345,pass:'pass'} =SELECT * FROM `customers` WHERE id='12345'**,** pass='pass',
error! so need replace the comma in "AND". like
SELECT * FROM `customers` WHERE ?,{id:12345,pass:'pass'} =SELECT * FROM `customers` WHERE id='12345' AND  pass='pass', 

SELECT * FROM `customers` WHERE id=? OR pass=?,{id:12345,pass:'pass'} =SELECT * FROM `customers` WHERE id='12345' OR pass='pass', //WORK (keep the old integration)
@dougwilson
Copy link
Member

Hi @devorel your use-case is beyond this module. You would likely be interested in the various SQL query-builder modules on npm like https://hiddentao.github.io/squel/ . This module is just for escaping values, not for fully building queries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants