PgSqlCaller support of RETURNING instead of count#3
Merged
Conversation
senid231
approved these changes
Jun 18, 2026
There was a problem hiding this comment.
Pull request overview
Adds an optional returning: keyword to PgSqlCaller::BulkUpdate so callers can read back selected columns from updated rows via SQL RETURNING, while preserving the existing row-count behavior when omitted.
Changes:
- Extend
BulkUpdate.callto acceptreturning:and return type-cast, Symbol-keyed row hashes when provided (otherwise returncmd_tuplescount as before). - Validate
returning:columns up front (non-empty; all must be real model columns) and qualify projections with thettable alias to avoid ambiguity. - Add specs + update README/CHANGELOG and bump gem version to
1.1.0.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
lib/pg_sql_caller/bulk_update.rb |
Implements returning: support (validation, SQL RETURNING clause, return-shape handling). |
spec/pg_sql_caller/bulk_update_spec.rb |
Adds coverage for returning rows, type-casting, composite unique_by, empty input, and validation errors. |
README.md |
Documents the new “reading back updated rows” behavior and clarifies return shapes and validations. |
CHANGELOG.md |
Adds 1.1.0 entry describing the new returning: feature and compare link. |
lib/pg_sql_caller/version.rb |
Bumps version from 1.0.0 to 1.1.0. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Add optional
returning:toPgSqlCaller::BulkUpdateLets
BulkUpdateread columns back from the updated rows via SQLRETURNING, instead of just a row count.Changes
BulkUpdate.call(model, attrs, returning: %i[id name])returns oneSymbol-keyed, type-cast hash per updated row ([]whenattrs_listis empty). A single column may be passed as aSymbol.talias (avoids ambiguity with theunnestsourcev).returning:columns are validated up front — empty or unknown columns raiseArgumentErrorbefore any SQL runs.returning:is omitted — still returns the affected-rowInteger.Tests / docs
unique_by, empty list, and validation errors, plus a regressionguard on the default count path. Full suite green, RuboCop clean.
Versioning
1.0.0 → 1.1.0(backward-compatible feature, SemVer MINOR).