entity

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MapIDField

func MapIDField[E Entity[I], I ID, P ePtr[E, I]](m *FieldMap[E], col *bsq.Column) error

Types

type Base

type Base[I ID] struct {
	// contains filtered or unexported fields
}

func (Base[I]) EntityID

func (eb Base[I]) EntityID() I

func (*Base[ID]) IDScanner

func (eb *Base[ID]) IDScanner() sql.Scanner

type DBRepo

type DBRepo[E Entity[I], I ID, P ePtr[E, I]] struct {
	// contains filtered or unexported fields
}

func NewDBRepo

func NewDBRepo[E Entity[I], I ID, P ePtr[E, I]](
	d bsq.Dialect,
	id *bsq.Column,
	m *FieldMap[E],
	hint any,
) (repo *DBRepo[E, I, P], err error)

func (*DBRepo[E, I, P]) Create

func (r *DBRepo[E, I, P]) Create(q sqlize.Querier, entity P) (*E, error)

func (*DBRepo[E, I, P]) CreateContext added in v0.9.0

func (r *DBRepo[E, I, P]) CreateContext(ctx context.Context, q sqlize.Querier, entity P) (*E, error)

func (*DBRepo[E, I, _]) Delete

func (r *DBRepo[E, I, _]) Delete(q sqlize.Querier, id I) error

func (*DBRepo[E, I, _]) DeleteContext added in v0.9.0

func (r *DBRepo[E, I, _]) DeleteContext(ctx context.Context, q sqlize.Querier, id I) error

func (*DBRepo[E, I, P]) Prepare

func (r *DBRepo[E, I, P]) Prepare(db *sql.DB) error

func (*DBRepo[E, I, P]) PrepareContext added in v0.9.0

func (r *DBRepo[E, I, P]) PrepareContext(ctx context.Context, db *sql.DB) error

func (*DBRepo[E, I, P]) Read

func (r *DBRepo[E, I, P]) Read(q sqlize.Querier, id I, reuse P) (*E, error)

func (*DBRepo[E, I, P]) ReadContext

func (r *DBRepo[E, I, P]) ReadContext(ctx context.Context, q sqlize.Querier, id I, reuse P) (*E, error)

func (*DBRepo[E, _, _]) Update

func (r *DBRepo[E, _, _]) Update(q sqlize.Querier, entity *E) error

func (*DBRepo[E, _, _]) UpdateContext added in v0.9.0

func (r *DBRepo[E, _, _]) UpdateContext(ctx context.Context, q sqlize.Querier, entity *E) error

type Entity

type Entity[I ID] interface {
	EntityID() I
}

type FieldMap

type FieldMap[E any] struct {
	// contains filtered or unexported fields
}

func (*FieldMap[E]) BindOut

func (m *FieldMap[E]) BindOut(e *E, hint any, reuse []any, cols ...*bsq.Column) []any

func (*FieldMap[E]) BindParams

func (m *FieldMap[E]) BindParams(e *E, hint any, reuse []any, cols ...*bsq.Column) []any

func (*FieldMap[E]) Clone

func (m *FieldMap[E]) Clone() *FieldMap[E]

func (*FieldMap[E]) FromSQL

func (m *FieldMap[E]) FromSQL(i int) MapFunc[E]

func (*FieldMap[E]) MapBoth

func (m *FieldMap[E]) MapBoth(col *bsq.Column, tofrom MapFunc[E]) error

func (*FieldMap[E]) MapFrom

func (m *FieldMap[E]) MapFrom(col *bsq.Column, from MapFunc[E]) error

func (*FieldMap[E]) MapMethods

func (m *FieldMap[E]) MapMethods(mode MapMode, cols ...*bsq.Column) error

func (*FieldMap[E]) MapTo

func (m *FieldMap[E]) MapTo(col *bsq.Column, to MapFunc[E]) error

func (*FieldMap[E]) MapToAndFrom

func (m *FieldMap[E]) MapToAndFrom(col *bsq.Column, toSQL, fromSQL MapFunc[E]) error

func (*FieldMap[E]) ToSQL

func (m *FieldMap[E]) ToSQL(i int) MapFunc[E]

type ID

type ID interface{ ID16 | ID32 | ID64 }

type ID16

type ID16 int16

func (*ID16) Scan

func (id *ID16) Scan(src any) error

func (ID16) Value

func (id ID16) Value() (driver.Value, error)

type ID32

type ID32 int32

func (*ID32) Scan

func (id *ID32) Scan(src any) error

func (ID32) Value

func (id ID32) Value() (driver.Value, error)

type ID64

type ID64 int64

func (*ID64) Scan

func (id *ID64) Scan(src any) error

func (ID64) Value

func (id ID64) Value() (driver.Value, error)

type MapCache added in v0.9.0

type MapCache[E Entity[I], I ID, P ePtr[E, I]] struct {
	Repo Repo[E, I]
	// contains filtered or unexported fields
}

MapCache is a simple write-through cache for repos that does not implement any eviction strategy. It only allows to explicitly [Clear] the cache. MapCache implements the Repo interface.

func NewMapCache added in v0.9.0

func NewMapCache[E Entity[I], I ID, P ePtr[E, I]](repo Repo[E, I]) *MapCache[E, I, P]

func (*MapCache[E, I, P]) Clear added in v0.9.0

func (mc *MapCache[E, I, P]) Clear()

func (*MapCache[E, I, P]) Create added in v0.9.0

func (mc *MapCache[E, I, P]) Create(q sqlize.Querier, entity P) (*E, error)

func (*MapCache[E, I, P]) CreateContext added in v0.9.0

func (mc *MapCache[E, I, P]) CreateContext(ctx context.Context, q sqlize.Querier, entity P) (*E, error)

func (*MapCache[E, I, P]) Delete added in v0.9.0

func (mc *MapCache[E, I, P]) Delete(q sqlize.Querier, id I) error

func (*MapCache[E, I, P]) DeleteContext added in v0.9.0

func (mc *MapCache[E, I, P]) DeleteContext(ctx context.Context, q sqlize.Querier, id I) error

func (*MapCache[E, I, P]) Read added in v0.9.0

func (mc *MapCache[E, I, P]) Read(q sqlize.Querier, id I, reuse P) (*E, error)

func (*MapCache[E, I, P]) ReadContext added in v0.9.0

func (mc *MapCache[E, I, P]) ReadContext(ctx context.Context, q sqlize.Querier, id I, reuse P) (*E, error)

func (*MapCache[E, I, P]) Update added in v0.9.0

func (mc *MapCache[E, I, P]) Update(q sqlize.Querier, entity P) error

func (*MapCache[E, I, P]) UpdateContext added in v0.9.0

func (mc *MapCache[E, I, P]) UpdateContext(ctx context.Context, q sqlize.Querier, entity P) error

type MapFunc

type MapFunc[E any] func(entity *E, hint any) any

type MapMode

type MapMode uint
const (
	MapAllTo MapMode = (1 << iota)
	MapAllFrom

	MapAll = MapAllTo | MapAllFrom
)

type Reader

type Reader[E Entity[I], I ID] interface {
	ReadContext(ctx context.Context, q sqlize.Querier, id I, reuse *E) (*E, error)
}

type Ref

type Ref[E Entity[I], I ID] struct {
	// contains filtered or unexported fields
}

func RefEntity

func RefEntity[E Entity[I], I ID](entity *E) Ref[E, I]

func RefID

func RefID[E Entity[I], I ID](r Reader[E, I], id I) Ref[E, I]

func (*Ref[E, ID]) Clear added in v0.9.0

func (ref *Ref[E, ID]) Clear()

func (*Ref[E, ID]) Get

func (ref *Ref[E, ID]) Get(db sqlize.Querier) (*E, error)

func (*Ref[E, ID]) GetContext

func (ref *Ref[E, ID]) GetContext(ctx context.Context, db sqlize.Querier) (entity *E, err error)

func (Ref[E, ID]) ID

func (ref Ref[E, ID]) ID() ID

func (Ref[E, ID]) Nil

func (ref Ref[E, ID]) Nil() bool

func (Ref[E, ID]) Resolved

func (ref Ref[E, ID]) Resolved() (is bool, entity *E)

func (*Ref[E, I]) Scanner

func (ref *Ref[E, I]) Scanner(r Reader[E, I]) refScanner[E, I]

func (*Ref[E, ID]) Set

func (ref *Ref[E, ID]) Set(entity *E)

func (*Ref[E, ID]) SetID

func (ref *Ref[E, ID]) SetID(r Reader[E, ID], id ID) error

func (*Ref[E, ID]) SetReader

func (ref *Ref[E, ID]) SetReader(r Reader[E, ID])

func (Ref[E, ID]) Value

func (ref Ref[E, ID]) Value() (driver.Value, error)

func (Ref[E, ID]) WithReader

func (ref Ref[E, ID]) WithReader(r Reader[E, ID]) (res Ref[E, ID])

type Repo

type Repo[E Entity[I], I ID] interface {
	Reader[E, I]
	Read(q sqlize.Querier, id I, reuse *E) (*E, error)
	Create(q sqlize.Querier, entity *E) (*E, error)
	CreateContext(ctx context.Context, q sqlize.Querier, entity *E) (*E, error)
	Update(q sqlize.Querier, entity *E) error
	UpdateContext(ctx context.Context, q sqlize.Querier, entity *E) error
	Delete(q sqlize.Querier, id I) error
	DeleteContext(ctx context.Context, q sqlize.Querier, id I) error
}

Jump to

Keyboard shortcuts

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