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

Only request returning attribute if client supports returning #1770

Merged
merged 3 commits into from
Feb 21, 2018

Conversation

larryprice
Copy link
Contributor

Introduction

knex 0.14.4 has been updated such that a warning is logged when using the returning attribute in a SQL dialect that does not support it. bookshelf always requests a returning attribute during an insert, which causes a flood of unwarranted warning messages whenever sqlite3 is used, and there is no way to tell bookshelf not to specify returning.

Motivation

When running my tests, I see warning messages like this flood my logs every time I call an insert:

console.log node_modules/knex/lib/helpers.js:90
  Knex:warning - .returning() is not supported by sqlite3 and will not have any effect.
console.log node_modules/knex/lib/helpers.js:90
  Knex:warning - .returning() is not supported by sqlite3 and will not have any effect.
console.log node_modules/knex/lib/helpers.js:90
  Knex:warning - .returning() is not supported by sqlite3 and will not have any effect.

Proposed solution

My solution is to check if the current client supports returning and request the idAttribute if and only if the support is available.

Current PR Issues

N/A

Alternatives considered

Also considered updating the client within knex to be able to do this logic. However, due to the fact that this change was implemented on the knex side, I have to assume that this is intended behavior.

Copy link
Member

@ricardograca ricardograca left a comment

Choose a reason for hiding this comment

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

Thanks for this, but the test suite must pass before this gets merged.

@larryprice
Copy link
Contributor Author

@ricardograca Thanks, I've updated the PR to pass the tests.

Copy link
Member

@ricardograca ricardograca left a comment

Choose a reason for hiding this comment

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

This is something that probably should be abstracted away in knex, but for now we'll handle it.

@ricardograca ricardograca merged commit c08fdf4 into bookshelf:master Feb 21, 2018
@sachincloudnaut
Copy link

Hi, I am struggling with returning keyword as AWS Redshift does not support it. Please let me know how should i configure in Bookshelf.js. I am using "bookshelf": "^1.0.0" , "knex": "^0.19.4" and "pg": "^7.12.1"
Select works but Insert, Update does not work due to Returning keyword being added at the end of query.

Please guide

@ricardograca
Copy link
Member

AWS Redshift is not in the list of clients that support RETURNING, so I have no idea why that is causing any issues. Can you provide more details?

@fl0w
Copy link
Collaborator

fl0w commented Sep 26, 2019

The problem is that that Redshift is pg compliant, and so I'm assuming @sachincloudnaut uses pg driver, which do support it - while Redshift does not. So Bookshelf thinks this is fine, Redshift disagrees.

@ricardograca
Copy link
Member

Let's continue the discussion in #2024.

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

Successfully merging this pull request may close these issues.

4 participants