feat(rows): add Rows::wasApplied() for lightweight transactions - #149
Merged
Conversation
A conditional write returns an `[applied]` column instead of an empty result. Until now the only way to read it was `$rows->first()['[applied]']`, which is easy to misspell and gives no help when the statement had no condition. `wasApplied()` reads the `[applied]` column of the first row. A statement with no condition has no such column, and the method then returns `true`, so a caller can ask this of any result. This matches `wasApplied()` in the Java driver and `was_applied` in the Python driver. The method reads the decoded row array, so it adds no driver call. The `[applied]` column stays readable through `first()` and array access, and old code keeps working. Also correct two stale statements in CLAUDE.md: - `*_arginfo.h` is gitignored and generated at build time by cmake/GenStubs.cmake. Do not commit it. - Upstream `gen_stub.php` fails on `declare(strict_types=1);`. Use tools/gen_stub/gen_arginfo.sh instead.
|
Tick the box to add this pull request to the merge queue (same as
|
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.
What
Adds
Cassandra\Rows::wasApplied(): bool.A conditional write returns an
[applied]column instead of an empty result. Until now the only way to read it was:Now:
Semantics
wasApplied()reads the[applied]column of the first row. A statement with no condition has no such column, and the method then returnstrue, so a caller can ask this of any result. This matcheswasApplied()in the Java driver andwas_appliedin the Python driver.falsemeans the condition failed, not that the row is present:wasApplied() === falsemeansIF NOT EXISTSIF EXISTSIF col = ?This is why the method is not named
exists()— the meaning inverts with the condition, which the driver cannot see.Implementation
The method reads the already-decoded row array, so it adds no
cass_*call and no round trip. The[applied]column stays readable throughfirst()and array access, so old code keeps working.Also in this PR
Two stale statements in
CLAUDE.md:*_arginfo.h. That file is gitignored (.gitignore:src/**/*_arginfo.h) and generated at build time bycmake/GenStubs.cmake.gen_stub.phpdirectly. Upstreamgen_stub.phpfails ondeclare(strict_types=1);withUnexpected node Stmt_Declare. The build callstools/gen_stub/gen_arginfo.sh, which strips the declare first.Tests
New
tests/Feature/Results/LightweightTransactionTest.php, 7 cases:IF NOT EXISTSthat wins, and one that loses (checks the current values come back)IF EXISTSagainst a missing rowIF col = ?SELECTexecuteAsync()All 13 tests in
tests/Feature/Resultspass against ScyllaDB, built with theDebugPHP8.4NTSpreset.