core

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2024 License: BSD-3-Clause-Clear Imports: 11 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SortRgx = regexp.MustCompile("(?i)(\\w+)(,(asC|dEsc))?;?")
View Source
var SuffixRgx = regexp.MustCompile("(" + SuffixStr + ")$")
View Source
var SuffixStr = "Gt|Ge|Lt|Le|Not|Ne|Eq|Null|NotIn|In|Like|NotLike|Contain|NotContain|Start|NotStart|End|NotEnd|Rx"

Functions

func Capitalize added in v0.2.2

func Capitalize(str string) string

func Close

func Close(db io.Closer)

func ConvertToColumnCase

func ConvertToColumnCase(fieldName string) string

func HasError

func HasError(err error) bool

func NoError

func NoError(err error) bool

func P

func P[T any](t T) *T

func ReadError

func ReadError(err error) *string

func ReadValue

func ReadValue(value reflect.Value) any

func RollbackFor

func RollbackFor(tc TransactionContext, origin error) error

func ToSnakeCase

func ToSnakeCase(fieldName string) string

func TransactionCallback

func TransactionCallback(tc TransactionContext, callback func(tc TransactionContext) error) (err error)

Types

type ColumnMetadata

type ColumnMetadata struct {
	Field      reflect.StructField
	IsId       bool
	ColumnName string
}

func BuildColumnMetas

func BuildColumnMetas(structType reflect.Type) []ColumnMetadata

type DataAccess

type DataAccess[E Entity] interface {
	Get(ctx context.Context, id any) (*E, error)
	Delete(ctx context.Context, id any) (int64, error)
	Query(ctx context.Context, query Query) ([]E, error)
	Count(ctx context.Context, query Query) (int64, error)
	DeleteByQuery(ctx context.Context, query Query) (int64, error)
	Page(ctx context.Context, query Query) (PageList[E], error)
	Create(ctx context.Context, entity *E) (int64, error)
	CreateMulti(ctx context.Context, entities []E) (int64, error)
	Update(ctx context.Context, entity E) (int64, error)
	Patch(ctx context.Context, entity E) (int64, error)
	PatchByQuery(ctx context.Context, entity E, query Query) (int64, error)
}

type Entity

type Entity interface {
	GetId() any

	// SetId set id to self.
	// self: the pointer points to the current entity.
	// id: type could be int, int64 or string so far.
	SetId(self any, id any) error
}

type Int64Id

type Int64Id struct {
	Id int64 `json:"id,omitempty"`
}

func NewInt64Id

func NewInt64Id(id int64) Int64Id

func (Int64Id) GetId

func (e Int64Id) GetId() any

func (Int64Id) SetId

func (e Int64Id) SetId(self any, id any) (err error)

type IntId

type IntId struct {
	Id int `json:"id,omitempty"`
}

func NewIntId

func NewIntId(id int) IntId

func (IntId) GetId

func (e IntId) GetId() any

func (IntId) SetId

func (e IntId) SetId(self any, id any) (err error)

type PageList

type PageList[D any] struct {
	List  []D   `json:"list"`
	Total int64 `json:"total"`
}

type PageQuery

type PageQuery struct {
	PageNumber *int    `json:"page,omitempty"`
	PageSize   *int    `json:"size,omitempty"`
	Sort       *string `json:"sort,omitempty"`
}

func (PageQuery) CalcOffset

func (pageQuery PageQuery) CalcOffset() int

func (PageQuery) GetPageNumber

func (pageQuery PageQuery) GetPageNumber() int

func (PageQuery) GetPageSize

func (pageQuery PageQuery) GetPageSize() int

func (PageQuery) GetSort

func (pageQuery PageQuery) GetSort() *string

func (PageQuery) NeedPaging

func (pageQuery PageQuery) NeedPaging() bool

type Query

type Query interface {
	GetPageNumber() int
	GetPageSize() int
	CalcOffset() int
	GetSort() *string
	NeedPaging() bool
}

type Response

type Response struct {
	Data    any     `json:"data,omitempty"`
	Success bool    `json:"success"`
	Error   *string `json:"error,omitempty"`
}

type RollbackError

type RollbackError struct {
	Err    error
	Origin error
}

func (*RollbackError) Error

func (e *RollbackError) Error() string

func (*RollbackError) Unwrap

func (e *RollbackError) Unwrap() error

type TransactionContext

type TransactionContext interface {
	context.Context
	driver.Tx
	Parent() context.Context
	SavePoint(name string) error
	RollbackTo(name string) error
}

type TransactionManager

type TransactionManager interface {
	GetClient() any
	StartTransaction(ctx context.Context) (TransactionContext, error)
	SubmitTransaction(ctx context.Context, callback func(tc TransactionContext) error) error
}

type TxDataAccess

type TxDataAccess[E Entity] interface {
	TransactionManager
	DataAccess[E]
}

Jump to

Keyboard shortcuts

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