db

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entity

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

Entity ..

func (*Entity) Mapper

func (e *Entity) Mapper() *entityMapper

Mapper ..

func (*Entity) WithMapper

func (e *Entity) WithMapper(em *entityMapper) *Entity

WithMapper ..

type Mapper

type Mapper[S Model[M], M any] interface {
	ToModel(ctx context.Context, src S) (*M, error)
	FromModel(ctx context.Context, src S, model *M) (S, error)
	ToList(ctx context.Context, list []S) ([]*M, error)
}

Mapper database model mapper

func NewMapper

func NewMapper[S Model[M], M any](_ context.Context) (Mapper[S, M], error)

NewMapper constructor

type Model

type Model[M any] interface {
	ToModel(ctx context.Context) (*M, error)
	FromModel(ctx context.Context, m *M) error
}

Model database model

type Repo

type Repo[S Model[M], M any] struct {
	// contains filtered or unexported fields
}

Repo entity repository

func NewRepo

func NewRepo[S Model[M], M any](ctx context.Context, cli *spanner.Client) (*Repo[S, M], error)

NewRepo constructor

func (*Repo[S, M]) NewEntity

func (r *Repo[S, M]) NewEntity() S

func (*Repo[S, M]) NewFromModel

func (r *Repo[S, M]) NewFromModel(ctx context.Context, m *M) (S, error)

func (*Repo[D, M]) SelectSingleWithBuilder

func (r *Repo[D, M]) SelectSingleWithBuilder(ctx context.Context, b sq.SelectBuilder) (*M, error)

SelectSingleWithBuilder executes squirrel select builder and returns mapped result

func (*Repo[D, M]) SelectWithBuilder

func (r *Repo[D, M]) SelectWithBuilder(ctx context.Context, b sq.SelectBuilder) ([]*M, error)

SelectWithBuilder executes squirrel select builder and returns mapped result

func (*Repo[S, M]) WithMapper

func (r *Repo[S, M]) WithMapper(m Mapper[S, M]) *Repo[S, M]

WithMapper sets repository model mapper

func (*Repo[S, M]) WithNew

func (r *Repo[S, M]) WithNew(fn func() S) *Repo[S, M]

Jump to

Keyboard shortcuts

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