-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
Handle undefined
and add IN
support
#172
base: master
Are you sure you want to change the base?
Conversation
undefined
and add IN
support
12f3b76
to
7d9a0ec
Compare
lib/database.js
Outdated
const formatWhere = (where) => | ||
where | ||
.filter((condition) => !!condition) | ||
.map((condition) => | ||
Object.entries(condition).filter((entry) => entry[1] !== undefined) | ||
) | ||
.filter((params) => params.length !== 0) | ||
.map(Object.fromEntries); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need this, at least in this PR, please describe a purpose of this code on separate issue
lib/database.js
Outdated
conjunction.push(`"${key}" ${operator} $${i++}`); | ||
args.push(value); | ||
if (value instanceof Array) { | ||
const list = value.map(() => `$${i++}`).join(','); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test fails at this line because you can't define function inside loop, so please rewrite using external call or nested loop
Here is another idea how to const ids = [1, 2, 3];
client.query('SELECT * FROM TableName WHERE id IN $1::int[]', [ids]); Try this as preferred alternative |
4b85e3d
to
9b87fa7
Compare
Handle these cases:
.select('Table', ['*'], {}) .select('Table', ['*'], { id: undefined }) .select('Table', ['*'], undefined) .select('Table', ['*'], { id: ['1', '2']})
.npm t
)npm run fmt
)