mysql_gorm

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDefaultGormDb added in v0.0.4

func NewDefaultGormDb(config Config) *gorm.DB

NewDefaultGormDb new a default gorm db,generally used in svc.NewServiceContext(c config.Config) *ServiceContext

func NewGormDbWithDriverConfig added in v0.0.4

func NewGormDbWithDriverConfig(driverConfig mysql.Config, config Config) *gorm.DB

Types

type Config

type Config struct {
	Path         string          // 服务器地址:端口
	Port         int             `json:",default=3306"` // 端口
	Config       string          // 高级配置
	Dbname       string          // 数据库名
	Username     string          // 数据库用户名
	Password     string          // 数据库密码
	MaxIdleConns int             // 空闲中的最大连接数
	MaxOpenConns int             // 打开到数据库的最大连接数
	LogMode      logger.LogLevel // 是否开启Gorm全局日志
	LogZap       bool            `json:"LogZap,optional,default=false"` // 是否通过zap写入日志文件
}

func (*Config) Dsn

func (m *Config) Dsn() string

type DefaultPage added in v0.1.8

type DefaultPage struct {
	Count int `json:"size"` //大小
	Page  int `json:"page"` //页码
}

type GormBaseModel added in v0.0.4

type GormBaseModel struct {
	CreatedAt int64          `json:"created_at" gorm:"autoCreateTime:milli"`
	UpdatedAt int64          `json:"updated_at" gorm:"autoUpdateTime:milli"`
	DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
}

type GormBaseModelWithId added in v0.0.4

type GormBaseModelWithId struct {
	Id uint `json:"id" gorm:"primaryKey"` //id
	GormBaseModel
}

type GormBaseModelWithOutLogicDelete added in v0.0.4

type GormBaseModelWithOutLogicDelete struct {
	CreatedAt int64 `json:"created_at" gorm:"autoCreateTime:milli"`
	UpdatedAt int64 `json:"updated_at" gorm:"autoUpdateTime:milli"`
}

type Page added in v0.1.7

type Page interface {
	GetCount() int
	GetPage() int
}

type PageData added in v0.1.7

type PageData[T any] struct {
	Total int64       `json:"total"` //总数
	Page  DefaultPage `json:"page"`  //页数信息
	Data  T           `json:"data"`  //数据
}

func FindPageData added in v0.1.7

func FindPageData[T any, M any](db *gorm.DB, page Page) (pagedata PageData[T], err error)

func FindPageDataNilModel added in v0.1.7

func FindPageDataNilModel[T any](db *gorm.DB, page Page) (pagedata PageData[T], err error)

func GetPageData added in v0.1.7

func GetPageData[T any, M any](db *gorm.DB, page Page, isScan bool) (pagedata PageData[T], err error)

func GetPageDataNilModel added in v0.1.7

func GetPageDataNilModel[T any](db *gorm.DB, page Page, isScan bool) (pagedata PageData[T], err error)

func ScanPageData added in v0.1.7

func ScanPageData[T any, M any](db *gorm.DB, page Page) (pagedata PageData[T], err error)

func ScanPageDataNilModel added in v0.1.7

func ScanPageDataNilModel[T any](db *gorm.DB, page Page) (pagedata PageData[T], err error)

func (PageData[T]) MarshalBinary added in v0.1.7

func (p PageData[T]) MarshalBinary() ([]byte, error)

Jump to

Keyboard shortcuts

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