Support anonymous struct in ToStruct type resolution#5
Merged
Conversation
Rename findVarTypeName to findVarType, returning (string, *ast.StructType) to handle both named types and anonymous structs. When an anonymous struct is found, extract spanner tags directly from the AST StructType node. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…lved When row.ToStruct(&v) is detected but the variable's type cannot be resolved (e.g. declared outside the callback), show a specific message instead of the generic "could not detect" error. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
var v struct { ... }のような無名構造体でrow.ToStruct(&v)するパターンに対応findVarTypeNameをfindVarTypeにリネームし、戻り値を(string, *ast.StructType)に変更設計の背景
row.ToStructでは名前付き型だけでなく、無名構造体を使うパターンも一般的。従来のfindVarTypeNameは型名(string)のみ返す設計だったため、型名を持たない無名構造体を扱えなかった。戻り値を
(string, *ast.StructType)に拡張することで、無名構造体の場合は AST のStructTypeノードから直接タグを抽出できるようにした。既存のextractTagsFromStructTypeをそのまま再利用しており、変更は最小限に抑えられている。Test plan
TestScan_ToStructAnonymousStruct: 無名構造体 +row.ToStructでマッチTestScan_ToStructAnonymousStructMismatch: 無名構造体 + SELECT カラム不一致でエラーgo test ./... -count=1)🤖 Generated with Claude Code