mysql

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDsn

func GetDsn(c Config) string

func NewDB

func NewDB(dsn string) (*gorm.DB, error)

NewDB 从配置文件读取数据库配置

func NewDefaultDB

func NewDefaultDB() (*gorm.DB, error)

NewDefaultDB 从env环境读取数据库配置

Types

type Association added in v1.0.10

type Association struct {
	Query string
	Args  interface{}
}

Association 关联模型结构体

type BaseMapper

type BaseMapper[T any] struct {
	Associations []Association // 关联
}

func (*BaseMapper[T]) Delete

func (m *BaseMapper[T]) Delete(entity T) error

Delete 删除

func (*BaseMapper[T]) Detail

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

Detail 详情

func (*BaseMapper[T]) First added in v1.0.10

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

First 单条记录

func (*BaseMapper[T]) Insert

func (m *BaseMapper[T]) Insert(entity *T) error

Insert 新增

func (*BaseMapper[T]) List

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

List 列表

func (*BaseMapper[T]) ListWithPage added in v1.0.10

func (m *BaseMapper[T]) ListWithPage(entity *T, page, pageSize int) (res []T, err error)

ListWithPage 列表带分页

func (*BaseMapper[T]) Update

func (m *BaseMapper[T]) Update(entity *T, omits ...interface{}) error

Update 更新

type Config

type Config struct {
	User     string `json:"user" xml:"user" yaml:"user" form:"user"`
	Password string `json:"password" xml:"password" yaml:"password" form:"password"`
	Host     string `json:"host" xml:"host" yaml:"host" form:"host"`
	Port     string `json:"port" xml:"port" yaml:"port" form:"port"`
	Database string `json:"database" xml:"database" yaml:"database" form:"database"`
	Charset  string `json:"charset" xml:"charset" yaml:"charset" form:"charset"`
}

Config 连接数据库

Jump to

Keyboard shortcuts

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