-
Notifications
You must be signed in to change notification settings - Fork 22
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
Don't return lastID when primary key is TEXT type solve #13 #38
base: master
Are you sure you want to change the base?
Conversation
I just stumbled upon this PR, may I say something about it? |
@gms1 I'm not an expert of sqlite, I greatly appreciate any suggestion or review. |
@slnode test please |
+1, I think |
I run the tests locally, |
Could this PR be merged now? @jannyHou |
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.
LGTM.
Ping @jannyHou |
@jannyHou Could you please merge this PR? |
Hi @jacko, apologies for the delayed reply. We're in the midst of migrating the CI pipelines over to public infrastructure as part of LoopBack 4 becoming an OpenJS Foundation project. I'll see if I can get this merged after the CI pipeline migration is completed. |
Description
This PR fix the issue #13 returning wrong id when the primary column is not a INTEGER type.
Sqlite3 has a built-in feature for retrieving the lastID on INSERT statement.
It's use here https://github.com/strongloop-community/loopback-connector-sqlite3/blob/master/lib/sqlite3.js#L202
But in the documentation of Sqlite3 https://sqlite.org/c3ref/last_insert_rowid.html the lastID contains the last rowid inserted but when your primary key is not integer you have two primary key : the primary key define in schema and the sqlite3 internal rowid.
So when we have on INSERT the lastID=an integer and the real id the token which is override by the dao https://github.com/strongloop/loopback-datasource-juggler/blob/master/lib/dao.js#L410.
Solution
Add
SQLite3.prototype._isPrimaryKeyText
returning true when the primary key is TEXT.Edit
SQLite3.prototype.getInsertedId
for returning undefined when primary key is TEXT.Related issues
Checklist
guide