Skip to content

Conversation

rhnvrm
Copy link
Member

@rhnvrm rhnvrm commented Sep 27, 2025

Summary

Improve variable naming and documentation in the writeResults function to make the SQL row scanning logic clearer and more maintainable.

Changes

File: internal/core/core.go

Variable Renaming:

  • resColsrowValues (holds actual data values)
  • resPointersscanPointers (holds pointers for scanning)

Documentation Update:

  • Replaced unclear comment with detailed explanation of the indirection pattern
  • Added clear documentation explaining why the pointer pattern is needed

Before:

// Gymnastics to read arbitrary types from the row.
var (
    resCols     = make([]interface{}, numCols)
    resPointers = make([]interface{}, numCols)
)

After:

// Create indirection for scanning arbitrary column types.
// sql.Rows.Scan() requires pointers to write into, but we need the actual values for WriteRow().
// Solution: scanPointers holds pointers to each element in rowValues, allowing Scan() to
// write through the pointers while we use the actual values from rowValues.
var (
    rowValues    = make([]interface{}, numCols)
    scanPointers = make([]interface{}, numCols)
)

Impact

  • ✅ No functional changes - pure readability improvement
  • ✅ Clearer variable names that express their purpose
  • ✅ Better documentation explaining the data flow pattern
  • ✅ Easier code maintenance and understanding

The variable names now clearly express that one slice holds the actual data while the other holds pointers for the scanning operation.

Rename variables for clarity:
- resCols → rowValues (holds actual data values)
- resPointers → scanPointers (holds pointers for scanning)

Update documentation to clearly explain the indirection pattern:
sql.Rows.Scan() requires pointers to write into, but we need the actual
values for WriteRow(). Solution: scanPointers holds pointers to each
element in rowValues, allowing Scan() to write through the pointers
while we use the actual values from rowValues.

No functional changes - pure readability improvement.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant