doug-martin/goqu

`goqu:"omitempty"` not omit empty field.

BhautikChudasama opened this issue · 2 comments

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.

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

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

Can confirm that also worked for me on v9.19.0