storage

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 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 UnmarshalJSON added in v1.2.0

func UnmarshalJSON[T any](data string) (T, error)

Helper function, similar to ScanJSON but directly returns the unmarshalled value.

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

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 any] func(string) (T, error)

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

type DiscriminatorFunc added in v1.2.0

type DiscriminatorFunc[T any] func(T) string

Function used to extract a discriminator from a value.

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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