entity

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2023 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Example (IsZero)
type thing struct{}
var e any
fmt.Println(isZero(e))
e = &thing{}
fmt.Println(isZero(e))
fmt.Println(isZero(&thing{}))
fmt.Println(isZero((*thing)(nil)))
fmt.Println(isZero(thing{}))
Output:

true
false
false
true
true

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func MapIDField

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

Types

type Base

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

func (Base[_, ID]) EntityID

func (eb Base[_, ID]) EntityID() ID

func (*Base[_, ID]) IDScanner

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

func (*Base[E, ID]) SQLizeReader

func (eb *Base[E, ID]) SQLizeReader() Reader[E, ID]

func (*Base[E, ID]) SetSQLizeReader

func (eb *Base[E, ID]) SetSQLizeReader(rd Reader[E, ID])

type DBRepo

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

func NewDBRepo

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

func (*DBRepo[E, I]) Create

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

func (*DBRepo[E, ID]) Delete

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

func (*DBRepo[E, I]) Prepare

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

func (*DBRepo[E, ID]) Read

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

func (*DBRepo[E, ID]) ReadContext

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

func (*DBRepo[E, ID]) Update

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

type Entity

type Entity[I ID] interface {
	EntityID() I
	IDScanner() sql.Scanner
}

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

func (*FieldMap[E]) MapFrom

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

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

func (*FieldMap[E]) MapToAndFrom

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

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 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[I ID, E Entity[I]](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]) Get

func (ref *Ref[E, ID]) Get(db sqlize.Querier) (entity E, err 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)

func (*Ref[E, ID]) SetReader

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

func (*Ref[E, ID]) SetRef

func (ref *Ref[E, ID]) SetRef(r Ref[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]
	Create(q sqlize.Querier, entity E) (E, error)
	Update(q sqlize.Querier, entity E) error
	Delete(q sqlize.Querier, id I) error
}

Jump to

Keyboard shortcuts

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