entity

package
v0.7.1-alpha Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2023 License: AGPL-3.0 Imports: 7 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

View Source
const IDSeqMax32 = 4194303 // 0x3f_ffff
View Source
const IDSeqMax64 = 281474976710655 // 0xffff_ffffffff
View Source
const IDTypeMax32 = 511 // 0x1ff
View Source
const IDTypeMax64 = 32767 // 0x7fff

Variables

This section is empty.

Functions

func MapIDField

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

func NotNoRows

func NotNoRows(err error) error

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

type Entity32 = Entity[ID32]

type Entity64

type Entity64 = Entity[ID64]

type FieldMap

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

func (*FieldMap[E]) Clone

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

func (*FieldMap[E]) FromSQL

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

func (*FieldMap[E]) MapBoth

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

func (*FieldMap[E]) MapFrom

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

TODO twisted dependency?

func (*FieldMap[E]) MapTo

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

TODO twisted dependency?

func (*FieldMap[E]) MapToAndFrom

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

func (*FieldMap[E]) ToSQL

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

type ID

type ID interface {
	ID32 | ID64
}

type ID32

type ID32 int32

ID32 is the 32-bit ID type.

func MakeID32

func MakeID32(t TypeID, s uint32) (ID32, error)

MakeID32 creates an ID32 from the TypeID t and the sequence value s.

func MustMakeID32

func MustMakeID32(t TypeID, s uint32) ID32

MustMakeID32 panics if MakeID32 returns an error.

func NoRowsNoErr32

func NoRowsNoErr32(id ID32, err error) (ID32, error)

NoRowsNoErr32 returns sqlize.NoID, nil when err is sql.ErrNoRows

func (*ID32) Scan

func (id *ID32) Scan(src interface{}) error

func (ID32) Type

func (id ID32) Type() TypeID

Type returns the TypeID from id.

func (ID32) Value

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

type ID64

type ID64 int64

ID64 is the 64-bit ID type.

func MakeID64

func MakeID64(t TypeID, s uint64) (ID64, error)

MakeID64 creates an ID64 from the TypeID t and the sequence value s.

func MustMakeID64

func MustMakeID64(t TypeID, s uint64) ID64

MustMakeID64 panics if MakeID64 returns an error.

func NoRowsNoErr64

func NoRowsNoErr64(id ID64, err error) (ID64, error)

NoRowsNoErr64 returns sqlize.NoID, nil when err is sql.ErrNoRows

func (*ID64) Scan

func (id *ID64) Scan(src interface{}) error

func (ID64) Type

func (id ID64) Type() TypeID

Type returns the TypeID from id.

func (ID64) Value

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

type Reader

type Reader[E Entity[I], I ID] interface {
	Read(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]) 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
}

type TypeID

type TypeID = uint16

To support ploymorphism, IDs consist of a TypeID part and a sequence part. The number of bits for both parts depend on the number of bits in the ID type. Currently only ID32 and ID64, i.e. int32 and int64, are supported ID types. A valid type id must be > 0.

type TypeTable

type TypeTable struct {
	// contains filtered or unexported fields
}

func NewTypeTable

func NewTypeTable(conn sqlize.Querier, table string) (res TypeTable, err error)

func (TypeTable) ForEach

func (idt TypeTable) ForEach(do func(tid TypeID, tag string) (done bool)) (hasDone bool)

func (TypeTable) ID

func (idt TypeTable) ID(tag string) TypeID

func (TypeTable) Tag

func (idt TypeTable) Tag(tid TypeID) string

Jump to

Keyboard shortcuts

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