entity_crud

package
v0.7.1-alpha1 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2024 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindSimple

func BindSimple[I any](binder *binding.Binder, simple *Simple[I], opts ...any)

func Create

func Create(tableName string, callbacks *CreateCallbacks) binding.ServiceFunc[string]

func CreateTx

func CreateTx(tableName string, callbacks *CreateCallbacks) binding.ServiceFunc[string]

func Delete

func Delete(tableName string, callbacks *DeleteCallbacks) binding.ServiceFunc[any]

func DeleteTx

func DeleteTx(tableName string, callbacks *DeleteCallbacks) binding.ServiceFunc[any]

func GetByID

func GetByID[O any](tableName string, callbacks *GetByIDCallbacks[O]) binding.ServiceFunc[O]

func Query

func Query[O any](tableName string, callbacks *QueryCallbacks[O], conditionFieldCallback ConditionFieldCallback) binding.ServiceFunc[response.InfosData[O]]

func Update

func Update(tableName string, callbacks *UpdateCallbacks) binding.ServiceFunc[any]

func UpdateTx

func UpdateTx(tableName string, callbacks *UpdateCallbacks) binding.ServiceFunc[any]

Types

type ConditionFieldCallback

type ConditionFieldCallback func(conditions *sql.Conditions, fieldName string, columnName string, value any) (hasDeal bool)

type CreateCallbacks added in v0.2.3

type CreateCallbacks struct {
	Prepare         func(e entity.Entity, i *infrastructure.Infrastructure) (map[string]any, error)
	Before          func(e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error
	After           func(e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error
	OnSuccessReturn func(e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, id string) (string, error)
	OnErrorReturn   func(e entity.Entity, prepared map[string]any, err error, i *infrastructure.Infrastructure) (string, error)
}

type CreateOption added in v0.2.3

type CreateOption func(options *CreateOptions)

func WithCreateCallbacks

func WithCreateCallbacks(callbacks *CreateCallbacks) CreateOption

func WithCreateMiddlewares

func WithCreateMiddlewares(middlewares []api.Handler) CreateOption

func WithCreateTx

func WithCreateTx() CreateOption

func WithDisableCreate

func WithDisableCreate() CreateOption

type CreateOptions added in v0.2.3

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

type DeleteCallbacks added in v0.2.3

type DeleteCallbacks struct {
	Prepare         func(e entity.Entity, i *infrastructure.Infrastructure) (map[string]any, error)
	Before          func(e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error
	After           func(e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error
	OnSuccessReturn func(e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure) error
	OnErrorReturn   func(e entity.Entity, prepared map[string]any, err error, i *infrastructure.Infrastructure) error
}

type DeleteOption added in v0.2.3

type DeleteOption func(options *DeleteOptions)

func WithDeleteCallbacks

func WithDeleteCallbacks(callbacks *DeleteCallbacks) DeleteOption

func WithDeleteMiddlewares

func WithDeleteMiddlewares(middlewares []api.Handler) DeleteOption

func WithDeleteTx

func WithDeleteTx() DeleteOption

func WithDisableDelete

func WithDisableDelete() DeleteOption

type DeleteOptions added in v0.2.3

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

type GetByIDCallbacks added in v0.3.0

type GetByIDCallbacks[O any] struct {
	Before          func(e entity.Entity, i *infrastructure.Infrastructure) error
	After           func(e entity.Entity, i *infrastructure.Infrastructure) error
	OnSuccessReturn func(e entity.Entity, i *infrastructure.Infrastructure, output O) (O, error)
	OnErrorReturn   func(e entity.Entity, err error, i *infrastructure.Infrastructure) (O, error)
}

type GetByIDOption added in v0.3.0

type GetByIDOption[I any] func(options *GetByIDOptions[I])

func WithDisableGetByID added in v0.3.0

func WithDisableGetByID[I any]() GetByIDOption[I]

func WithGetByIDCallbacks

func WithGetByIDCallbacks[I any](callbacks *GetByIDCallbacks[I]) GetByIDOption[I]

func WithGetByIDMiddlewares

func WithGetByIDMiddlewares[I any](middlewares []api.Handler) GetByIDOption[I]

type GetByIDOptions added in v0.3.0

type GetByIDOptions[I any] struct {
	// contains filtered or unexported fields
}

type QueryCallbacks added in v0.2.3

type QueryCallbacks[O any] struct {
	Before          func(e entity.Entity, i *infrastructure.Infrastructure) error
	After           func(e entity.Entity, i *infrastructure.Infrastructure) error
	OnSuccessReturn func(e entity.Entity, i *infrastructure.Infrastructure, output response.InfosData[O]) (response.InfosData[O], error)
	OnErrorReturn   func(e entity.Entity, err error, i *infrastructure.Infrastructure) (response.InfosData[O], error)
}

type QueryOption added in v0.2.3

type QueryOption[I any] func(options *QueryOptions[I])

func WithDisableQuery

func WithDisableQuery[I any]() QueryOption[I]

func WithQueryCallbacks

func WithQueryCallbacks[I any](callbacks *QueryCallbacks[I]) QueryOption[I]

func WithQueryConditionFieldCallback

func WithQueryConditionFieldCallback[I any](callback ConditionFieldCallback) QueryOption[I]

func WithQueryMiddlewares

func WithQueryMiddlewares[I any](middlewares []api.Handler) QueryOption[I]

type QueryOptions added in v0.2.3

type QueryOptions[I any] struct {
	// contains filtered or unexported fields
}

type Simple

type Simple[I any] struct {
	// 使用的领域实体,注意是Entity类型
	Entity entity.Entity

	// 数据库Schema
	Schema string

	// 创建使用的请求参数
	CreateJsonBody request.Params

	// 删除使用的请求参数,注意是WithID类型
	DeleteQueryParams request.IDRequestParam

	// 更新使用的请求参数,注意是WithID类型
	UpdateJsonBody request.IDRequestParam

	// 查询使用的请求参数,注意是Query类型
	QueryQueryParams request.QueryRequestParams

	// 根据ID查询使用的请求参数,注意是WithID类型
	GetByIDQueryParams request.IDRequestParam
	// contains filtered or unexported fields
}

Simple 实体CRUD的Bind参数 I 为查询相关接口返回的Info类型

type UpdateCallbacks added in v0.2.3

type UpdateCallbacks struct {
	Prepare         func(e entity.Entity, i *infrastructure.Infrastructure) (map[string]any, error)
	Before          func(e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error
	After           func(e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error
	OnSuccessReturn func(e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure) error
	OnErrorReturn   func(e entity.Entity, prepared map[string]any, err error, i *infrastructure.Infrastructure) error
}

type UpdateOption added in v0.2.3

type UpdateOption func(options *UpdateOptions)

func WithDisableUpdate

func WithDisableUpdate() UpdateOption

func WithUpdateCallbacks

func WithUpdateCallbacks(callbacks *UpdateCallbacks) UpdateOption

func WithUpdateMiddlewares

func WithUpdateMiddlewares(middlewares []api.Handler) UpdateOption

func WithUpdateTx

func WithUpdateTx() UpdateOption

type UpdateOptions added in v0.2.3

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

Jump to

Keyboard shortcuts

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