Documentation ¶
Index ¶
- Variables
- func ScanJSON[T any](value any, target *T) error
- func UnmarshalJSON[T any](data string) (T, error)
- func ValueJSON[T any](v T) (driver.Value, error)
- type DiscriminatedMapper
- type DiscriminatedMapperFunc
- type DiscriminatorFunc
- type Mapper
- type Merger
- type Paginated
- type Scanner
- type SecretString
Constants ¶
This section is empty.
Variables ¶
var ErrCouldNotUnmarshalGivenType = errors.New("could not unmarshal given type")
Functions ¶
func UnmarshalJSON ¶ added in v1.2.0
Helper function, similar to ScanJSON but directly returns the unmarshalled value.
Types ¶
type DiscriminatedMapper ¶ added in v1.1.0
type DiscriminatedMapper[T any] struct { // contains filtered or unexported fields }
Mapper struct to be able to rehydrate discriminated types. Discriminated types represents an extensible type known through a discriminator value. Building a specific mapper makes it easy to reconstruct a specific type from a discriminator and raw data. Without it, retrieving dynamic types from the database is a nightmare. With this solution though, it's not that bad ;)
func NewDiscriminatedMapper ¶ added in v1.1.0
func NewDiscriminatedMapper[T any]( extractor DiscriminatorFunc[T], ) *DiscriminatedMapper[T]
Builds a new mapper configuration to hold a discriminated type.
func (*DiscriminatedMapper[T]) From ¶ added in v1.1.0
Rehydrate a discriminated type from a raw value.
func (*DiscriminatedMapper[T]) Register ¶ added in v1.1.0
func (m *DiscriminatedMapper[T]) Register(concreteType T, mapper DiscriminatedMapperFunc[T])
Register a new concrete type available to the mapper.
type DiscriminatedMapperFunc ¶ added in v1.1.0
Function used to map from a raw value to a discriminated type.
type DiscriminatorFunc ¶ added in v1.2.0
Function used to extract a discriminator from a value.
type Merger ¶
type Merger[TParent, TChildren any] func(TParent, TChildren) TParent // Merger function to handle relations by configuring how a child should be merged into its parent
type Paginated ¶
type Paginated[T any] struct { Data []T `json:"data"` Page int `json:"page"` IsFirstPage bool `json:"first_page"` IsLastPage bool `json:"last_page"` PerPage int `json:"per_page"` Total int `json:"total"` }
Represents a paginated data set.
type Scanner ¶
type Scanner interface { // Scan current row into the destination fields. // The things to keep in mind is the order used when scanning which should always be the // same as the order of fields returned by the underlying implementation (for a database, // the order of SELECT columns). // // IMPORTANT: it will fails if the type of a monad.Value is not a primitive type or // does not implements the sql.Scanner interface. Scan(...any) error }
Deserialize a storage row to field. This is the interface making possible the rehydration of domain entities from the db since all fields are private to enforce invariants and encapsulation.
Since domain store will always constructs an aggregate as a whole, it makes the process relatively easy to keep under control.
type SecretString ¶ added in v1.2.0
type SecretString string
Represents a specific string that should be kept secret and should never be exposed. To do that, it implements the MarshalJSON interface to always return the same constant (See SecretStringPublicValue).
func (SecretString) MarshalJSON ¶ added in v1.2.0
func (s SecretString) MarshalJSON() ([]byte, error)
func (*SecretString) Scan ¶ added in v1.2.0
func (s *SecretString) Scan(src any) error
Implements the Scan interface to enable the use of this type in a monad.