Skip to content
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

goqu:"omitempty" not omit empty field. #394

Open
1 of 3 tasks
BhautikChudasama opened this issue Nov 11, 2023 · 2 comments
Open
1 of 3 tasks

goqu:"omitempty" not omit empty field. #394

BhautikChudasama opened this issue Nov 11, 2023 · 2 comments

Comments

@BhautikChudasama
Copy link

Describe the bug
I want to omit the zerovalue string. I am using example mentioned code.

To Reproduce

type item struct {
	FirstName string  `db:"first_name" goqu:"omitempty"`
	LastName  string  `db:"last_name" goqu:"omitempty"`
	Address1  *string `db:"address1" goqu:"omitempty"`
	Address2  *string `db:"address2" goqu:"omitempty"`
	Address3  *string `db:"address3" goqu:"omitempty"`
}
address1 := "114 Test Addr"
var emptyString string
sql, args, _ := goqu.Update("items").Set(
	item{
		FirstName: "Test First Name",
		LastName:  "", // will omit zero field
		Address1:  &address1,
		Address2:  &emptyString,
		Address3:  nil, // will omit nil pointer
	},
).ToSQL()
fmt.Println(sql, args)

Actual Output

UPDATE "items" SET "address1"='114 Test Addr',"address2"='',"address3"=NULL,"first_name"='Test First Name',"last_name"='' []

Expected behavior
The last name should not add.

UPDATE "items" SET "address1"='114 Test Addr',"address2"='',"first_name"='Test First Name' []

Dialect:

  • postgres
  • mysql
  • sqlite3

Additional context
Add any other context about the problem here.

@BhautikChudasama BhautikChudasama changed the title goqu:"omitempty not omit empty field. goqu:"omitempty" not omit empty field. Nov 11, 2023
@yura1338
Copy link

Got same bug in v9.18.0. v9.19.0 is OK

@TatarinAlba
Copy link

Got same bug in v9.18.0. v9.19.0 is OK

Can confirm that also worked for me on v9.19.0

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

No branches or pull requests

3 participants