Skip to content

feat: no ErrNoRows when scan nil struct ptr and nil map and nil builtin type ptr#1379

Open
CyJaySong wants to merge 3 commits into
uptrace:masterfrom
CyJaySong:feat-NoErrNoRowsWhenScanNilStructPtr
Open

feat: no ErrNoRows when scan nil struct ptr and nil map and nil builtin type ptr#1379
CyJaySong wants to merge 3 commits into
uptrace:masterfrom
CyJaySong:feat-NoErrNoRowsWhenScanNilStructPtr

Conversation

@CyJaySong
Copy link
Copy Markdown
Contributor

@CyJaySong CyJaySong commented May 9, 2026

previous writing styles

user := new(User)
err := db.NewSelect().Model(usert). Where("id = ?", 1).Scan(ctx)
// If there is no data that meets the criteria,err = sql.ErrNoRows, user != nil

new feature

var user *User
err := db.NewSelect().Model(&usert). Where("id = ?", 1).Scan(ctx)
If there is no data that meets the criteria,err = nil, user = nil

var users map[string]any
err := db.NewSelect().Model((*User)(nil)). Where("id = ?", 1).Scan(ctx, &users)
If there is no data that meets the criteria,err = nil, users = nil

var phone *string
err := db.NewSelect().Model((*User)(nil)). Where("id = ?", 1).Column("phone").Scan(ctx, &phone)
If there is no data that meets the criteria,err = nil, phone = nil

Compatible with previous writing styles

@CyJaySong
Copy link
Copy Markdown
Contributor Author

@Aoang Hi Bro,look here

Comment thread query_base.go
@CyJaySong CyJaySong force-pushed the feat-NoErrNoRowsWhenScanNilStructPtr branch from 1df5a46 to c7b489d Compare May 14, 2026 02:39
@CyJaySong CyJaySong requested a review from bevzzz May 14, 2026 02:51
@CyJaySong CyJaySong force-pushed the feat-NoErrNoRowsWhenScanNilStructPtr branch from c7b489d to 9e80321 Compare May 14, 2026 09:46
Comment thread model.go Outdated
Comment thread query_base.go Outdated
@CyJaySong CyJaySong changed the title feat: no ErrNoRows when scan nil struct ptr feat: no ErrNoRows when scan nil struct ptr and nil map May 15, 2026
Comment thread model.go
@CyJaySong CyJaySong force-pushed the feat-NoErrNoRowsWhenScanNilStructPtr branch from a02c4b2 to 385b0a6 Compare May 20, 2026 10:35
@CyJaySong CyJaySong changed the title feat: no ErrNoRows when scan nil struct ptr and nil map feat: no ErrNoRows when scan nil struct ptr and nil map and builtin type May 20, 2026
@CyJaySong
Copy link
Copy Markdown
Contributor Author

@bevzzz

@CyJaySong CyJaySong changed the title feat: no ErrNoRows when scan nil struct ptr and nil map and builtin type feat: no ErrNoRows when scan nil struct ptr and nil map and nil builtin type ptr May 20, 2026
@bevzzz
Copy link
Copy Markdown
Collaborator

bevzzz commented May 20, 2026

@CyJaySong I'll take another pass at the PR tomorrow, just to make sure I understand the changes well. Thanks for your patience and the effort you're putting in contributing to Bun.

@CyJaySong
Copy link
Copy Markdown
Contributor Author

CyJaySong commented May 21, 2026

@bevzzz Thanks for your recognition. I‘m looking forward to a smooth merger

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.

2 participants