mysql

package
v0.0.0-...-2f28ce4 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Mysql

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtendParse

func ExtendParse(where Extend, extendField string) (whereSQL string, vals []any, err error)

自定义where条件解析逻辑

func OrderParse

func OrderParse(order Order, fields ...string) (orderSQL string, err error)

自定义order条件解析逻辑

func WhereBuild

func WhereBuild(where map[string]any) (whereSQL string, vals []any, err error)

sql build where

func WhereParse

func WhereParse(where Where, fields ...string) (whereSQL string, vals []any, err error)

自定义where条件解析逻辑

Types

type Extend

type Extend [][3]string

type MySQL

type MySQL struct {
	HostName        string `mapstructure:"HostName"`        // 服务器地址
	HostPort        string `mapstructure:"HostPort"`        // 端口
	DataBase        string `mapstructure:"DataBase"`        // 数据库名
	UserName        string `mapstructure:"UserName"`        // 用户名
	PassWord        string `mapstructure:"PassWord"`        // 密码
	Charset         string `mapstructure:"Charset"`         // 数据库编码默认采用utf8
	Prefix          string `mapstructure:"Prefix"`          // 数据库表前缀
	Timeout         int    `mapstructure:"Timeout"`         // 设置最大打开的连接数,默认值为0表示不限制
	MaxOpenConns    int    `mapstructure:"MaxOpenConns"`    // 设置最大打开的连接数,默认值为0表示不限制
	MaxIdleConns    int    `mapstructure:"MaxIdleConns"`    // 连接池里面允许Idel的最大连接数
	ConnMaxLifetime int    `mapstructure:"ConnMaxLifetime"` // 设置一个连接的最长生命周期
	LogLevel        int    `mapstructure:"LogLevel"`        // SQL日志级别(Silent:1, Error:2, Warn:3, Info:4)
	// contains filtered or unexported fields
}

MySQL配置

func (*MySQL) Connect

func (config *MySQL) Connect() (gormDb *gorm.DB)

SetMaxOpenConns: 设置最大打开的连接数,默认值为0表示不限制。控制应用于数据库建立连接的数量,避免过多连接压垮数据库。 SetMaxIdleConns: 连接池里面允许Idel(空闲)的最大连接数, 这些Idel的连接 就是并发时可以同时获取的连接,也是用完后放回池里面的互用的连接, 从而提升性能。 SetConnMaxLifetime: 设置一个连接的最长生命周期,因为数据库本身对连接有一个超时时间的设置,如果超时时间到了数据库会单方面断掉连接,此时再用连接池内的连接进行访问就会出错, 因此这个值往往要小于数据库本身的连接超时时间

func (*MySQL) SetMaxOpenConns

func (config *MySQL) SetMaxOpenConns(n int) error

设置最大连接数

func (*MySQL) Table2Struct

func (config *MySQL) Table2Struct(tableName string) (structContent string, err error)

mysql生成struct结构体实例

type NullType

type NullType byte
const (

	// IsNull the same as `is null`
	IsNull NullType
	// IsNotNull the same as `is not null`
	IsNotNull
)

type Order

type Order [][2]string
type Search struct {
	Where  [][3]any
	Extend [][3]string
	Order  [][2]string
}

搜索结构

func (*Search) ExtendParse

func (search *Search) ExtendParse(extendField string) (whereSQL string, vals []any, err error)

自定义where条件解析逻辑

func (*Search) LikeParse

func (search *Search) LikeParse(keyword string, fields ...string) (likeSQL string)

自定义like条件解析逻辑

func (*Search) OrderParse

func (search *Search) OrderParse(fields ...string) (orderSQL string, err error)

自定义order条件解析逻辑

func (*Search) WhereParse

func (search *Search) WhereParse(fields ...string) (whereSQL string, vals []any, err error)

自定义where条件解析逻辑

type Where

type Where [][3]any

Jump to

Keyboard shortcuts

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