Skip to content

Query scanner single column #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/passed-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ TestSubQueryWithHaving
TestScanNullValue
TestQueryWithTableAndConditions
TestQueryWithTableAndConditionsAndAllFields
#TestQueryScannerWithSingleColumn
TestQueryScannerWithSingleColumn
TestQueryResetNullValue
TestQueryError
TestQueryScanToArray
Expand Down
25 changes: 19 additions & 6 deletions tests/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1352,19 +1352,32 @@ type DoubleInt64 struct {
data int64
}

func (t *DoubleInt64) Scan(val interface{}) error {
switch v := val.(type) {
case int64:
t.data = v * 2
func (t *DoubleInt64) Scan(v any) error {
if v == nil {
t.data = 0
return nil
}
switch x := v.(type) {
case int64:
t.data = x * 2
case float64:
t.data = int64(x) * 2
default:
return fmt.Errorf("DoubleInt64 cant not scan with:%v", v)
if s, ok := x.(fmt.Stringer); ok { // e.g., godror.Number
n, err := strconv.ParseInt(strings.TrimSpace(s.String()), 10, 64)
if err != nil {
return fmt.Errorf("DoubleInt64: %w", err)
}
t.data = n * 2
return nil
}
return fmt.Errorf("DoubleInt64: cannot scan %T", v)
}
return nil
}

// https://github.com/go-gorm/gorm/issues/5091
func TestQueryScannerWithSingleColumn(t *testing.T) {
t.Skip()
user := User{Name: "scanner_raw_1", Age: 10}
DB.Create(&user)

Expand Down
Loading