zsc

package module
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2023 License: MIT Imports: 13 Imported by: 0

README

Zoox Service Container

@TODO

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Version = "1.2.5"

Version is the version of this package.

Functions

func DBCreate

func DBCreate[T any](one *T) (*T, error)

func DBDelete

func DBDelete[T any](id uint) (err error)

func DBExists added in v1.0.2

func DBExists[T any](where map[any]any) (bool, error)

func DBFind added in v1.0.1

func DBFind[T any](where map[any]any) (data []*T, err error)

func DBFindByID added in v1.0.2

func DBFindByID[T any](id uint) (*T, error)

func DBFindOne added in v1.0.1

func DBFindOne[T any](where map[any]any) (*T, error)

func DBFindOneAndDelete added in v1.0.2

func DBFindOneAndDelete[T any](where map[any]any) (*T, error)

func DBFindOneAndUpdate added in v1.0.1

func DBFindOneAndUpdate[T any](where map[any]any, callback func(*T)) (*T, error)

func DBFindOneByIDAndDelete added in v1.0.2

func DBFindOneByIDAndDelete[T any](id uint) (*T, error)

func DBFindOneByIDAndUpdate added in v1.0.2

func DBFindOneByIDAndUpdate[T any](id uint, callback func(*T)) (*T, error)

func DBFindOneByIDOrCreate added in v1.0.2

func DBFindOneByIDOrCreate[T any](id uint, callback func(*T)) (*T, error)

func DBFindOneOrCreate added in v1.0.2

func DBFindOneOrCreate[T any](where map[any]any, callback func(*T)) (*T, error)

func DBGetMany

func DBGetMany[T any](ids []uint) (data []*T, err error)

func DBGetOrCreate added in v1.0.1

func DBGetOrCreate[T any](where map[any]any, callback func(*T)) (*T, error)

func DBHas

func DBHas[T any](id uint) bool

func DBList

func DBList[T any](page, pageSize uint, where *Where, orderBy *OrderBy) (data []*T, total int64, err error)

func DBListAll added in v1.2.3

func DBListAll[T any](where *Where, orderBy *OrderBy) (data []*T, err error)

func DBRetrieve

func DBRetrieve[T any](id uint) (*T, error)

func DBSave

func DBSave[T any](one *T) error

func DBUpdate

func DBUpdate[T any](id uint, uc func(*T)) (err error)

func GetController

func GetController[T any](id string) T

func GetDB

func GetDB() *gorm.DB

func GetModel

func GetModel[T any](id string) T

func GetService

func GetService[T any](id string) T

func LoadDB

func LoadDB(engine string, dsn string, opts ...*LoadDBOptions) (err error)

func Register

func Register(namespace string, model Model, service Service, controller Controller)

func RegisterController

func RegisterController(name string, m Controller)

func RegisterModel

func RegisterModel(name string, m Model)

func RegisterService

func RegisterService(name string, m Service)

Types

type Controller

type Controller interface {
	Name() string
	//
	// Model() container.Container
	Service() container.Container
	//
	Params(ctx *zoox.Context) *Params
	// //
	// Success(ctx *zoox.Context, data interface{})
	// FailWithError(ctx *zoox.Context, err zoox.HTTPError)
	User(ctx *zoox.Context) interface{}
}

type ControllerImpl

type ControllerImpl struct {
}

func (*ControllerImpl) FailWithError

func (c *ControllerImpl) FailWithError(ctx *zoox.Context, err zoox.HTTPError)

func (*ControllerImpl) Params

func (c *ControllerImpl) Params(ctx *zoox.Context) *Params

func (*ControllerImpl) Service

func (c *ControllerImpl) Service() container.Container

func (*ControllerImpl) Success

func (c *ControllerImpl) Success(ctx *zoox.Context, data interface{})

func (*ControllerImpl) User

func (c *ControllerImpl) User(ctx *zoox.Context) interface{}

type ListParams

type ListParams struct {
	Page     uint
	PageSize uint
	Where    *Where
	OrderBy  *OrderBy
}

type ListParamsDefault added in v1.0.6

type ListParamsDefault struct {
	Page     uint
	PageSize uint
}

type LoadDBOptions added in v1.2.4

type LoadDBOptions struct {
	IsProd bool
}

type Model

type Model interface {
	ModelName() string
	Model() container.Container
}

type ModelImpl

type ModelImpl struct {
	ID        uint           `gorm:"primarykey" json:"id"`
	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"`
	//
	Creator  uint `json:"creator"`
	Modifier uint `json:"modifier"`
}

func (*ModelImpl) Model

func (m *ModelImpl) Model() container.Container

func (*ModelImpl) ModelName

func (m *ModelImpl) ModelName() string

type OrderBy

type OrderBy []OrderByOne

func (*OrderBy) Build added in v1.0.6

func (w *OrderBy) Build() string

func (*OrderBy) Debug

func (w *OrderBy) Debug()

func (*OrderBy) Get

func (w *OrderBy) Get(key string) (bool, bool)

func (*OrderBy) Length added in v1.0.6

func (w *OrderBy) Length() int

func (*OrderBy) Set

func (w *OrderBy) Set(key string, IsDESC bool)

type OrderByOne

type OrderByOne struct {
	Key    string
	IsDESC bool
}

type Page

type Page struct {
	Page     int64 `query:"page,default=1"`
	PageSize int64 `query:"pageSize,default=10"`
}

type Params

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

func NewParams

func NewParams(ctx *zoox.Context) *Params

func (*Params) GetList

func (c *Params) GetList(defaults ...*ListParamsDefault) (*ListParams, error)

func (*Params) ID

func (c *Params) ID() (uint, error)

func (*Params) OrderBy

func (c *Params) OrderBy() *OrderBy

func (*Params) Page

func (c *Params) Page() (uint, error)

func (*Params) PageSize

func (c *Params) PageSize() (uint, error)

func (*Params) Where

func (c *Params) Where() *Where

type Service

type Service interface {
	Name() string
	Model() container.Container
	Service() container.Container
}

type ServiceImpl

type ServiceImpl struct {
}

func (*ServiceImpl) Model

func (s *ServiceImpl) Model() container.Container

func (*ServiceImpl) Name

func (s *ServiceImpl) Name() string

func (*ServiceImpl) Service

func (s *ServiceImpl) Service() container.Container

type SetWhereOptions

type SetWhereOptions struct {
	IsFuzzy bool
	IsNot   bool
	IsIn    bool
}

type Where

type Where []WhereOne

func (*Where) Build added in v1.0.4

func (w *Where) Build() (string, []interface{})

func (*Where) Debug

func (w *Where) Debug()

func (*Where) Get

func (w *Where) Get(key string) (interface{}, bool)

func (*Where) Length added in v1.0.4

func (w *Where) Length() int

func (*Where) Set

func (w *Where) Set(key string, value interface{}, opts ...*SetWhereOptions)

type WhereOne

type WhereOne struct {
	Key     string
	Value   interface{}
	IsFuzzy bool
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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