storage

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2023 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCouldNotUnmarshalGivenType = errors.New("could not unmarshal given type")

Functions

func ScanJSON

func ScanJSON[T any](value any, target *T) error

Ease the scan of a json serialized field.

func ValueJSON added in v1.1.0

func ValueJSON[T any](v T) (driver.Value, error)

Ease the valueing of a json serialized field by calling json.Marshal and returning a string as accepted as a valid driver.Value.

Types

type Discriminated added in v1.1.0

type Discriminated interface {
	Discriminator() string
}

Represents an extensible type known through a discriminator value when implementing the Scanner interface as no sense since we don't know which type is used in our entity.

type DiscriminatedMapper added in v1.1.0

type DiscriminatedMapper[T Discriminated] map[string]DiscriminatedMapperFunc[T]

Mapper struct to be able to rehydrate discriminated types.

func NewDiscriminatedMapper added in v1.1.0

func NewDiscriminatedMapper[T Discriminated]() DiscriminatedMapper[T]

Builds a new mapper configuration to hold a discriminated type.

func (DiscriminatedMapper[T]) From added in v1.1.0

func (m DiscriminatedMapper[T]) From(discriminator, value string) (T, error)

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

type DiscriminatedMapperFunc[T Discriminated] func(string) (T, error)

Function used to map from a raw value to a discriminated type.

type Mapper

type Mapper[T any] func(Scanner) (T, error) // Mapper function from a simple Scanner to an object of type T

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 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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL