Repository navigation
feat!: return last_insert_rowid as i64, as sqlx-sqlite does - #14
Merged
Merged
Conversation
`QueryResult::last_insert_rowid` now returns `i64` rather than `Option<i64>`, with 0 when the statement inserted no row -- the signature of sqlx-sqlite's `SqliteQueryResult`, so code written against it compiles unchanged on D1 and Durable Objects. That includes sqlc-gen-sqlx's SQLite output, whose `:execlastid` functions return `result.last_insert_rowid()` as an `i64`. `QueryResult::new` takes an `i64` to match. Rowids start at 1 unless a row is given 0 explicitly, so 0 is unambiguous in practice; `RETURNING` is the way to be certain. Extending a result still keeps the last non-zero rowid, so a trailing SELECT does not erase the INSERT before it. BREAKING CHANGE: `last_insert_rowid()` returns `i64`, and 0 where it returned `None`. `QueryResult::new` takes `last_insert_rowid: i64`.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
QueryResult::last_insert_rowid()returnsOption<i64>, but sqlx-sqlite'sSqliteQueryResult::last_insert_rowid()returnsi64. Code written against sqlx-sqlite therefore doesn't compile on D1 or Durable Objects, even though the drivers otherwise follow sqlx-sqlite wherever JavaScript doesn't force a difference (sqlx-cloudflare-core/src/types.rs). JavaScript doesn't force this one.This also affects sqlc-gen-sqlx's SQLite output: its
:execlastidfunctions end inOk(result.last_insert_rowid())returningi64.Change
last_insert_rowid()returnsi64,0when the statement inserted no row.QueryResult::newtakes ani64to match.meta.last_row_idto0. DO passeslast_insert_rowid()through, and a statement that wrote nothing reports0, as before but no longerNone.SELECTdoesn't erase theINSERTbefore it.Rowids start at 1 unless a row is given 0 explicitly, so
0is unambiguous in practice;RETURNINGis the way to be certain. sqlx-sqlite reports a stale rowid after aSELECT, so0is the more accurate answer of the two.Breaking
feat!:last_insert_rowid()returnsi64, and0where it returnedNone. release-please should bump to 0.2.0.Verification
make check lint testpasses, host and wasm32.mainalready has.feat/engine-sqlitefork branch), with only theAsExecutorimpls retargeted, compiles against bothD1andDo. The:execlastidfunction compiles unchanged.make test-workernot run locally; CI runs it.