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

Handle undefined and add IN support #172

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

AliusDieMorietur
Copy link

@AliusDieMorietur AliusDieMorietur commented Jul 15, 2021

Handle these cases: .select('Table', ['*'], {}) .select('Table', ['*'], { id: undefined }) .select('Table', ['*'], undefined) .select('Table', ['*'], { id: ['1', '2']}).

  • tests and linter show no problems (npm t)
  • tests are added/updated for bug fixes and new features
  • code is properly formatted (npm run fmt)
  • description of changes is added in CHANGELOG.md
  • update .d.ts typings

@AliusDieMorietur AliusDieMorietur changed the title Handle undefined Handle undefined and add IN support Jul 16, 2021
lib/database.js Outdated Show resolved Hide resolved
lib/database.js Outdated
Comment on lines 7 to 17
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);
Copy link
Member

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(',');
Copy link
Member

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

@tshemsedinov tshemsedinov mentioned this pull request Jul 16, 2021
5 tasks
@tshemsedinov
Copy link
Member

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

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

Successfully merging this pull request may close these issues.

2 participants