Don't return lastID when primary key is TEXT type solve #13#38
Don't return lastID when primary key is TEXT type solve #13#38HugoPoi wants to merge 3 commits intoloopbackio:masterfrom
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 |
|
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._isPrimaryKeyTextreturning true when the primary key is TEXT.Edit
SQLite3.prototype.getInsertedIdfor returning undefined when primary key is TEXT.Related issues
Checklist
guide