entity

package
v0.11.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2025 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsID

func IsID[I ID](id I) bool

func NoID

func NoID[I ID]() I

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[I]) EntityIDScanner

func (eb *Base[I]) EntityIDScanner() sql.Scanner

func (*Base[I]) FromSQLid

func (eb *Base[I]) FromSQLid(any) any

func (*Base[I]) ToSQLid

func (eb *Base[I]) ToSQLid(any) any

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.CreateDialect,
	id *bsq.Column,
	hint any,
	opts ...bsq.MapOption[P],
) (repo *DBRepo[E, I, P], err error)

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

func (r *DBRepo[E, I, P]) Create(cmd sqlize.CtxCmd, 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, cmd sqlize.CtxCmd, entity P) (*E, error)

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

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

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

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

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

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

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

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

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

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

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

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

type Entity

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

type ID

type ID interface {
	comparable
	driver.Valuer
}

Pointer to ID types must implement sql.Scanner

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
Example
type Dummy struct{ Base[ID32] }
var d Dummy
fmt.Println(d.FromSQLid(nil).(sql.Scanner).Scan(int64(4711)))
fmt.Println(d.ToSQLid(nil))
Output:

<nil>
4711

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(cmd sqlize.CtxCmd, 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, cmd sqlize.CtxCmd, entity P) (*E, error)

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

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

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

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

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

func (mc *MapCache[E, I, P]) Read(cmd sqlize.CtxCmd, 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, cmd sqlize.CtxCmd, id I, reuse P) (*E, error)

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

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

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

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

type NumID

type NumID interface{ ID16 | ID32 | ID64 }

type PolyID

type PolyID[N NumID] struct {
	// contains filtered or unexported fields
}

func NewPolyID

func NewPolyID[N NumID](typebits int) (PolyID[N], error)

func (*PolyID[N]) ID

func (pi *PolyID[N]) ID(t, s N) N

func (*PolyID[N]) Type

func (pi *PolyID[N]) Type(id N) N

type Reader

type Reader[E Entity[I], I ID] interface {
	ReadContext(ctx context.Context, cmd sqlize.CtxCmd, 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.CtxCmd) (*E, error)

func (*Ref[E, ID]) GetContext

func (ref *Ref[E, ID]) GetContext(ctx context.Context, db sqlize.CtxCmd) (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(cmd sqlize.CtxCmd, id I, reuse *E) (*E, error)
	Create(cmd sqlize.CtxCmd, entity *E) (*E, error)
	CreateContext(ctx context.Context, cmd sqlize.CtxCmd, entity *E) (*E, error)
	Update(cmd sqlize.CtxCmd, entity *E) error
	UpdateContext(ctx context.Context, cmd sqlize.CtxCmd, entity *E) error
	Delete(cmd sqlize.CtxCmd, id I) error
	DeleteContext(ctx context.Context, cmd sqlize.CtxCmd, id I) error
}

Jump to

Keyboard shortcuts

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