Skip to the content.

Struct Tags

goqu reads two struct tags when mapping structs to and from columns.

type User struct {
	ID        int64   `db:"id" goqu:"skipinsert,skipupdate"`
	FirstName string  `db:"first_name"`
	Address   *string `db:"address" goqu:"omitnil"`
	Notes     string  `db:"notes" goqu:"defaultifempty"`
}

goqu options

Option Applies to Effect
skipinsert INSERT The field is not included in INSERT statements. See Inserting.
skipupdate UPDATE The field is not included in UPDATE statements. See Updating.
skipselect SELECT The field is not added to the columns selected for the struct (Select(&s) and ScanStruct/ScanStructs without an explicit Select). The column is still scanned when it is selected, e.g. a column that comes from a join.
defaultifempty INSERT When the field is the zero value, DEFAULT is used instead of the value. See Inserting.
omitnil INSERT/UPDATE The field is skipped when it is a nil pointer. Useful for partial updates.
omitempty INSERT/UPDATE The field is skipped when it is the zero value (including nil pointers).

Options can be combined, e.g. goqu:"skipinsert,skipupdate".

skipinsert, skipupdate and skipselect on a nested struct field apply to every column flattened out of that struct (e.g. Bar Bar goqu:”skipinsert”`` skips "bar"."b" on insert).

Notes