dbx

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exists

func Exists(ctx context.Context, db *gorm.DB) (bool, error)

func FindOne

func FindOne(ctx context.Context, db *gorm.DB, opts QueryOptions, out any) (bool, error)

func FindPage

func FindPage(ctx context.Context, db *gorm.DB, pp PaginationParam, opts QueryOptions, out any) (int64, error)

func GetDB

func GetDB(ctx context.Context, defDB *gorm.DB) *gorm.DB

func InitDB

func InitDB(ctx context.Context) (*gorm.DB, func(), error)

func LikeParameter

func LikeParameter(v string) string

func NewDB

func NewDB(c Config) (*gorm.DB, error)

Types

type Config

type Config struct {
	Debug        bool
	DBType       string
	DSN          string
	MaxLifetime  int
	MaxIdleTime  int
	MaxOpenConns int
	MaxIdleConns int
	TablePrefix  string
	Resolver     []ResolverConfig
}

type Direction

type Direction string
const (
	ASC  Direction = "ASC"
	DESC Direction = "DESC"
)

type OrderByParam

type OrderByParam struct {
	Field     string
	Direction Direction
}

type OrderByParams

type OrderByParams []OrderByParam

func (OrderByParams) ToSQL

func (p OrderByParams) ToSQL() string

type PaginationParam

type PaginationParam struct {
	Pagination bool `form:"-" default:"true"`
	OnlyCount  bool `form:"-"`
	PageNum    int  `form:"page_num"`
	PageSize   int  `form:"page_size" binding:"max=100"`
}

type PaginationResult

type PaginationResult struct {
	Items    any   `json:"items"`
	Total    int64 `json:"total"`
	PageNum  int   `json:"pageNum"`
	PageSize int   `json:"pageSize"`
}

func WrapPageQuery

func WrapPageQuery(ctx context.Context, db *gorm.DB, pp PaginationParam, opts QueryOptions, out any) (*PaginationResult, error)

type QueryOptions

type QueryOptions struct {
	SelectFields []string
	OmitFields   []string
	OrderFields  OrderByParams
}

type ResolverConfig

type ResolverConfig struct {
	DBType   string
	Sources  []string
	Replicas []string
	Tables   []string
}

type Trans

type Trans struct {
	DB *gorm.DB
}

func (*Trans) Exec

func (t *Trans) Exec(ctx context.Context, fn TransFunc) error

type TransFunc

type TransFunc func(context.Context) error

Jump to

Keyboard shortcuts

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