database

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DBDriverNotSupport = errors.New("database driver not support")
)

Functions

func Pagination

func Pagination[T any](pager *Pager[T]) func(db *gorm.DB) *gorm.DB

Types

type BaseMapper

type BaseMapper[T any] struct {
	DB *Database
}

func NewMapper

func NewMapper[T any](db *Database, model T) *BaseMapper[T]

func (*BaseMapper[T]) Count

func (m *BaseMapper[T]) Count(entity T) (count int64, err error)

func (*BaseMapper[T]) Delete

func (m *BaseMapper[T]) Delete(entity T, db ...*gorm.DB) error

func (*BaseMapper[T]) Detail

func (m *BaseMapper[T]) Detail(entity T) (res T, err error)

func (*BaseMapper[T]) Insert

func (m *BaseMapper[T]) Insert(entity T, db ...*gorm.DB) error

func (*BaseMapper[T]) List

func (m *BaseMapper[T]) List(entity T, order ...string) (res []T, err error)

func (*BaseMapper[T]) Page

func (m *BaseMapper[T]) Page(entity T, page, size int64) (res *Pager[T], err error)

func (*BaseMapper[T]) Update

func (m *BaseMapper[T]) Update(entity T, fields map[string]interface{}, db ...*gorm.DB) error

type BaseModel

type BaseModel struct {
	CreatedAt time.Time      `json:"createdAt" swaggerignore:"true"`
	UpdatedAt time.Time      `json:"updatedAt" swaggerignore:"true"`
	DeleteAt  gorm.DeletedAt `json:"-" swaggerignore:"true"`
}

type Database

type Database struct {
	*gorm.DB
}

func GetDB

func GetDB() *Database

func NewDatabase

func NewDatabase(cfg *config.Config) *Database

type Pager

type Pager[T any] struct {
	CurrentPage int64 `json:"current"`
	PageSize    int64 `json:"size"`
	Total       int64 `json:"total"`
	Data        []T   `json:"data"`
}

Jump to

Keyboard shortcuts

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