.returning('foo') returns primary key instead of 'foo' column in sqlite3 #1660
Comments
Sorry for the confusion. At the beginning of I guess we could be a little clearer in the wording there, but the implication is that this feature isn't supported by We could also look into throwing an error to fail when trying to use this feature on an unsupported client. Thoughts? |
Ah I see that makes sense. I think an error might be helpful for people in the future. This would simply trigger the .catch? I actually miscopied what is in the docs. It actually says: // Returns [2] in "mysql", "sqlite"; [2, 3] in "postgresql"
knex('books')
.returning('id')
.insert([{title: 'Great Gatsby'}, {title: 'Fahrenheit 451'}])
Outputs:
insert into `books` (`title`) values ('Great Gatsby'), ('Fahrenheit 451') So the sqlite mention confused me. Removing that part might be more obvious. Thanks for the quick response! |
An error would be nice to have. This is not the first time that people has been confused with features, which are supported only by some db engines. |
Not sure if error should be really be thrown, since it makes hard to generic libraries/wrappers over knex. The wrapper implementation will have to check the connection config before chaining the Also people get confused, since they ignore the documentation text above the code blocks |
@thetutlage I don't see how creating erroneus query is a better choice than throwing and error and yes generic wrapper should make sure that underlying DB supports the If wrapper wants to be really generic, it won't use I'm not a big fan of the historical-JS habit of allowing users to do invalid code with silent errors / noop functionality. |
Have we reached a conclusion to this issue? Throwing an error, silently ignorning, and printing a warning during query compilation are all valid options imo. |
I would propose following:
|
Aside from the issue at hand I don't know methods by hand that aren't supported by specific dialects, so in the spirit of not escalating the issue any further, I will only add a warning for
|
As of 0.14.4, the warning is printed every time I run migrate() in test even though the |
I have an app using a psql database and some unit tests which use
I know that |
Hey chaps. This is fine, but I found that the mssql dialect does not return the primary key when you leave off the |
@GeekyDeaks Also postgresql does that... Goog to know that mssql does that also. I've been meaning to make proposal about changing Anyways I need to discuss about it with other contributors first. Currently I've been just fixing other mssql/tedious driver stability problems. |
Thanks @elhigu - would you implement it in the processReponse() of the dialect? i.e. like in
If so, I might take a look at this over the weekend and submit a PR. I'm only just getting up to speed with knex though, so it might take me a little longer |
Process response is not enough, since also built query needs to be modified, I don't think this can be implemented before it has been properly discussed first. There are some benefits/drawback that needs to be considered. |
ah, yeah - was poking around under the debugger and noticed that. I can workaround by checking the client dialect for now. |
That's great; but how do you get the ID of a created, updated, or deleted record in Sqlite3? ...Never mind. It's in the docs. |
I have a node app that I switch back and forth between sqlite3 and postgres.
When I my npm script for using sqlite3 I get back a primary key rather than the column I specified.
Postgres is returning the correct column.
No matter what I put in for
.returning('*'/['uuid']/'name' .....)
I seem to be getting the primary key in sqlite3.This is how the docs describe the intended behavior.
The Query in Question
Screenshot of data

Config File
This might be a bug or perhaps the docs are lacking. Either way I can try to take a look at it if a collaborator can point me in the right direction.
The text was updated successfully, but these errors were encountered: