Repository navigation
fix: Scan accepts raw 12-byte IDs from binary columns - #117
Merged
Merged
Conversation
Scan always used UnmarshalText, so BYTEA / binary drivers returning the 12-byte form failed. Route rawLen slices through FromBytes-style copy; keep text decoding for the base32 form.
There was a problem hiding this comment.
Pull request overview
Fixes xid.ID’s sql.Scanner implementation to correctly handle binary SQL column values that arrive as raw 12-byte IDs (e.g., BYTEA/BINARY), while preserving existing behavior for text/base32-encoded values.
Changes:
- Update
(*ID).Scanto accept raw 12-byte[]bytevalues by copying directly into the ID. - Keep the existing text/base32 decoding path for non-12-byte
[]byteandstringinputs. - Add a unit test covering scanning raw 12-byte values.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| id.go | Extends (*ID).Scan to accept raw 12-byte binary values in addition to base32 text. |
| id_test.go | Adds a regression test ensuring Scan succeeds for raw 12-byte IDs. |
💡 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.
Summary
(*ID).Scanalways calledUnmarshalText. Binary SQL columns (BYTEA, etc.) return the raw 12-byte form, which failed as invalid base32.If
len(val) == 12, copy bytes likeFromBytes; otherwise keep the text path.Test plan
go test -run TestIDDriverScan