entity_crud

package
v1.3.9 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 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, needCreateUserID bool, callbacks *CreateCallbacks, needTx bool) binding.ServiceFunc[string]

func Delete

func Delete(tableName string, callbacks *DeleteCallbacks, needTx bool) 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, orderBy string, callbacks *QueryCallbacks[O], conditionFieldCallback ConditionFieldCallback, formCustomConditionFunc FormCustomConditionFunc) binding.ServiceFunc[response.InfosData[O]]

func Update

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

Types

type ConditionFieldCallback

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

type CreateCallbacks added in v0.2.3

type CreateCallbacks struct {
	Prepare         func(c *api.Context, params request.Params, e entity.Entity, i *infrastructure.Infrastructure) (map[string]any, error)
	Before          func(c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error
	After           func(c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error
	OnSuccessReturn func(c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, id string) (string, error)
	OnErrorReturn   func(c *api.Context, params request.Params, 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 ...binding.Middleware) CreateOption

func WithCreateTx

func WithCreateTx() CreateOption

func WithCreateUserID added in v0.9.0

func WithCreateUserID() CreateOption

func WithDisableCreate

func WithDisableCreate() CreateOption

type CreateOptions added in v0.2.3

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

type CustomCondition added in v1.2.1

type CustomCondition struct {
	Conditions *sql.Conditions
	OrderBy    string
}

type DeleteCallbacks added in v0.2.3

type DeleteCallbacks struct {
	Prepare         func(c *api.Context, params request.Params, e entity.Entity, i *infrastructure.Infrastructure) (map[string]any, error)
	Before          func(c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error
	After           func(c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error
	OnSuccessReturn func(c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure) error
	OnErrorReturn   func(c *api.Context, params request.Params, 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 ...binding.Middleware) 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 FormCustomConditionFunc added in v1.2.1

type FormCustomConditionFunc func(c *api.Context, params request.Params, e entity.Entity, i *infrastructure.Infrastructure) (*CustomCondition, error)

type GetByIDCallbacks added in v0.3.0

type GetByIDCallbacks[O any] struct {
	Before          func(c *api.Context, params request.Params, e entity.Entity, i *infrastructure.Infrastructure) error
	After           func(c *api.Context, params request.Params, e entity.Entity, i *infrastructure.Infrastructure) error
	OnSuccessReturn func(c *api.Context, params request.Params, e entity.Entity, i *infrastructure.Infrastructure, output O) (O, error)
	OnErrorReturn   func(c *api.Context, params request.Params, 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 ...binding.Middleware) GetByIDOption[I]

type GetByIDOptions added in v0.3.0

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

type GlobalOption added in v0.8.0

type GlobalOption func(options *GlobalOptions)

func WithGlobalMiddlewares added in v0.8.0

func WithGlobalMiddlewares(middlewares ...binding.Middleware) GlobalOption

type GlobalOptions added in v0.8.0

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

type QueryCallbacks added in v0.2.3

type QueryCallbacks[O any] struct {
	Before          func(c *api.Context, params request.Params, e entity.Entity, i *infrastructure.Infrastructure) error
	After           func(c *api.Context, params request.Params, e entity.Entity, i *infrastructure.Infrastructure) error
	OnSuccessReturn func(c *api.Context, params request.Params, e entity.Entity, i *infrastructure.Infrastructure, output response.InfosData[O]) (response.InfosData[O], error)
	OnErrorReturn   func(c *api.Context, params request.Params, 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 WithQueryFormCustomConditionFunc added in v1.2.1

func WithQueryFormCustomConditionFunc[I any](formCustomConditionFunc FormCustomConditionFunc) QueryOption[I]

func WithQueryMiddlewares

func WithQueryMiddlewares[I any](middlewares ...binding.Middleware) QueryOption[I]

func WithQueryOrderBy added in v0.10.2

func WithQueryOrderBy[I any](orderBy string) 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(c *api.Context, params request.Params, e entity.Entity, i *infrastructure.Infrastructure) (map[string]any, error)
	Before          func(c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error
	After           func(c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error
	OnSuccessReturn func(c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure) error
	OnErrorReturn   func(c *api.Context, params request.Params, 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 WithLastUpdateUserID added in v0.9.0

func WithLastUpdateUserID() UpdateOption

func WithUpdateCallbacks

func WithUpdateCallbacks(callbacks *UpdateCallbacks) UpdateOption

func WithUpdateMiddlewares

func WithUpdateMiddlewares(middlewares ...binding.Middleware) 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