core

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: BSD-3-Clause-Clear Imports: 12 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Config = struct {
	TableFormat     string
	JoinIdFormat    string
	JoinTableFormat string
}{
	"t_%s",
	"%s_id",
	"a_%s_and_%s",
}
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 FormatJoinId added in v0.2.3

func FormatJoinId(domain string) string

func FormatJoinTable added in v0.2.3

func FormatJoinTable(domain1 string, domain2 string) string

func FormatTable added in v0.2.3

func FormatTable(domain string) string

func MapVirtualEntity added in v0.2.3

func MapVirtualEntity(ve string) string

func NoError

func NoError(err error) bool

func P

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

func ReadValue

func ReadValue(value reflect.Value) any

func RegisterJoinTable added in v0.2.3

func RegisterJoinTable(domain1 string, domain2 string, table string)

func RegisterVirtualEntity added in v0.2.3

func RegisterVirtualEntity(ve string, target string)

func RollbackFor

func RollbackFor(tc TransactionContext, origin error) error

func Ternary added in v0.3.0

func Ternary[T any](test bool, r1, r2 T) T

func ToSnakeCase

func ToSnakeCase(fieldName string) string

func TransactionCallback

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

Types

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 Entity) (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 EntityPath added in v0.2.3

type EntityPath struct {
	Path       []string
	Base       Relation
	Relations  []Relation
	EntityType reflect.Type
}

func BuildEntityPath added in v0.2.3

func BuildEntityPath(field reflect.StructField) *EntityPath

func BuildEntityPathStr added in v0.2.3

func BuildEntityPathStr(aep string) *EntityPath

type FieldMetadata added in v0.2.3

type FieldMetadata struct {
	Field      reflect.StructField
	IsId       bool
	ColumnName string
	EntityPath *EntityPath
}

func BuildFieldMetas added in v0.2.3

func BuildFieldMetas(structType reflect.Type) []FieldMetadata

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 {
	Page int    `json:"page,omitempty"`
	Size int    `json:"size,omitempty"`
	Sort string `json:"sort,omitempty"`
}

func (PageQuery) CalcOffset

func (pq PageQuery) CalcOffset() int

func (PageQuery) GetPageNumber

func (pq PageQuery) GetPageNumber() int

func (PageQuery) GetPageSize

func (pq PageQuery) GetPageSize() int

func (PageQuery) GetSort

func (pq PageQuery) GetSort() string

func (PageQuery) NeedPaging

func (pq PageQuery) NeedPaging() bool

type Query

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

type Relation added in v0.2.3

type Relation struct {
	Fk1, Fk2, At string
}

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] struct {
	TransactionManager
	DataAccess[E]
}

Jump to

Keyboard shortcuts

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