Documentation ¶
Index ¶
- type Partial
- func (m Partial[T]) Add(opts ...func(*T) []string) Partial[T]
- func (m Partial[T]) Apply(base T) *T
- func (m Partial[T]) Empty() bool
- func (m Partial[T]) Match(otherPtr *T) bool
- func (m Partial[T]) Merge(other Partial[T]) Partial[T]
- func (m *Partial[T]) SetApply(apply func(T) *T)
- func (m Partial[T]) Without(fieldNamesToRemove ...string) Partial[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Partial ¶
type Partial[T any] struct { Subject T FieldNames []string `json:"-"` // contains filtered or unexported fields }
Partial wraps a domain object of type T, and maintains a list of columns that have been set for the model.
Tracking columns allows us to control which fields we wish to create or update when calling gorm functions via the Querier, avoiding an issue with default field values and accidentally including columns in queries.
func New ¶
New builds a model from a domain object, tracking all the JSON fields of the model.
This should be used only for objects loaded from the database, where we know all the fields are populated correctly. It should not be used with user constructed domain objects, as those should be built directly into Partial's using their codegen'd builders.
func (Partial[T]) Add ¶
Add returns a new Partial with additional setters, taking precendence over whatever was previously set.
func (Partial[T]) Match ¶
Match checks if the given object matches against the fields that are set on the tracked model.
This helps check if applying the changes tracked in the model would result in any change, and is useful to check when building idempotent update methods.