goqu icon indicating copy to clipboard operation
goqu copied to clipboard

skipinsert and skipupdate have no effect on structs

Open mrwuzz opened this issue 2 years ago • 0 comments

Describe the bug The skipinsert and skipupdate tags are ignored for struct fields.

To Reproduce

type Foo struct {
	A   string `db:"a"`
	Bar Bar    `db:"bar" goqu:"skipinsert,skipupdate"`
}

type Bar struct {
	B string `db:"b"`
}

//...

db.Insert("foo").Rows(Foo{A: "a", Bar: Bar{B: "b"}}).ToSQL()
db.Update("foo").Set(Foo{A: "a", Bar: Bar{B: "b"}}).ToSQL()

Results in:

INSERT INTO "foo" ("a", "bar"."b") VALUES ('a', 'b')
UPDATE "foo" SET "a"='a',"bar"."b"='b'

Expected behavior The expected result is for the Bar field to be ignored in the INSERT and UPDATE statements, resulting in the following queries:

INSERT INTO "foo" ("a") VALUES ('a')
UPDATE "foo" SET "a"='a'

Dialect:

  • [X] postgres
  • [ ] mysql
  • [ ] sqlite3

Additional context One could set the db:"-" tag to ignore the Bar field on inserts and updates, but then the field would also be ignored by the ScanStruct() method, resulting in an error if the query result contains colums of Bar.

Another workaround is to set the goqu:"skipinsert,skipupdate" tags on the fields of the Bar struct, but then the fields would also be ignored when inserting or updating a Bar object directly.

mrwuzz avatar Sep 14 '22 08:09 mrwuzz