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

feat(postgres): native upsert #12301

Merged
merged 4 commits into from May 24, 2020
Merged

feat(postgres): native upsert #12301

merged 4 commits into from May 24, 2020

Conversation

sushantdhiman
Copy link
Contributor

@sushantdhiman sushantdhiman commented May 23, 2020

Pull Request check-list

Please make sure to review and check all of these items:

  • Does npm run test or npm run test-DIALECT pass with this change (including linting)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Have you added new tests to prevent regressions?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Did you update the typescript typings accordingly (if applicable)?
  • Did you follow the commit message conventions explained in CONTRIBUTING.md?

Description of change

Closes #11246
Fixes #4132
Fixes #12051
Fixes #9629
Fixes #9216

@sushantdhiman sushantdhiman requested a review from May 23, 2020
@codecov
Copy link

@codecov codecov bot commented May 23, 2020

Codecov Report

Merging #12301 into master will decrease coverage by 0.04%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #12301      +/-   ##
==========================================
- Coverage   96.34%   96.29%   -0.05%     
==========================================
  Files          95       95              
  Lines        9127     9127              
==========================================
- Hits         8793     8789       -4     
- Misses        334      338       +4     
Impacted Files Coverage Δ
lib/dialects/abstract/index.js 100.00% <ø> (ø)
lib/dialects/mysql/query-generator.js 97.56% <ø> (-0.06%) ⬇️
lib/dialects/postgres/query-generator.js 92.46% <ø> (-2.19%) ⬇️
lib/dialects/postgres/query-interface.js 98.92% <ø> (-0.02%) ⬇️
lib/dialects/sqlite/query-generator.js 96.50% <ø> (-0.14%) ⬇️
lib/dialects/abstract/query-generator.js 97.39% <100.00%> (+0.25%) ⬆️
lib/dialects/abstract/query-interface.js 93.76% <100.00%> (+0.17%) ⬆️
lib/dialects/mariadb/query.js 87.96% <100.00%> (+0.18%) ⬆️
lib/dialects/mssql/query-interface.js 100.00% <100.00%> (ø)
lib/dialects/mssql/query.js 94.62% <100.00%> (ø)
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8244a34...7b174eb. Read the comment docs.

Copy link
Contributor

@SimonSchick SimonSchick left a comment

Can't say much about the query logic changes, I'm not really a postgres user, some comments on the code though.

lib/dialects/abstract/query-interface.js Outdated Show resolved Hide resolved
lib/dialects/abstract/query-interface.js Outdated Show resolved Hide resolved
test/integration/model/upsert.test.js Outdated Show resolved Hide resolved
lib/dialects/abstract/query-generator.js Show resolved Hide resolved
lib/dialects/mssql/query-interface.js Outdated Show resolved Hide resolved
lib/dialects/mssql/query-interface.js Outdated Show resolved Hide resolved
lib/dialects/abstract/index.js Show resolved Hide resolved
lib/dialects/abstract/query-generator.js Show resolved Hide resolved
* @param {boolean} [options.returning=false] If true, fetches back auto generated values (Postgres only)
* @param {boolean} [options.returning=true] If true, fetches back auto generated values
Copy link
Member

@papb papb May 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work for all 5 dialects now?

Copy link
Contributor Author

@sushantdhiman sushantdhiman May 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except for mariadb, which does not support RETURINING * at all, in current 10.1 target version. But it wont fail

Copy link
Member

@papb papb May 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am confused, if it is not supported by MariaDB, then why could the following code be removed:

    if (options.returning === true && primaryKey) {
      const record = await this.findByPk(primaryKey, options);
      result = [record, created];

Copy link
Contributor Author

@sushantdhiman sushantdhiman May 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works but it is buggy, see linked issues. Plus one extra read from database. So I decided to not support this for mariadb.

test/config/config.js Show resolved Hide resolved
test/integration/model/upsert.test.js Outdated Show resolved Hide resolved
@sushantdhiman
Copy link
Contributor Author

@sushantdhiman sushantdhiman commented May 24, 2020

@papb I think I have taken care of all points raised by you, I am merging this PR. Let me know if you have any questions

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