mysql

package module
v0.0.0-...-e2cb540 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(conf Config) gorm.Dialector

New 根据配置创建一个新的 Gorm 数据库连接。 它支持通过 SSH 隧道进行数据库连接,如果配置中提供了 SSH 配置。

参数:

  • conf: 数据库和 SSH 连接的配置。

返回值:

  • gorm.Dialector: 用于 Gorm 以建立数据库连接的接口。

func Open

func Open(dsn string) gorm.Dialector

Open 根据给定的 DSN (数据源名称) 打开一个 MySQL 数据库连接。 它返回一个实现了 gorm.Dialector 接口的数据库连接对象,用于后续的数据库操作。 该函数实际上调用了 mysql 包中的 Open 函数来创建数据库连接。

参数:

  • dsn: 数据源名称 (Data Source Name) 的字符串,格式通常包括用户名、密码、主机、端口、数据库名等信息。

返回值:

  • gorm.Dialector: 一个可以与 GORM 框架配合使用的数据库连接对象。

Types

type Config

type Config struct {
	DriverName                    string         `json:"driverName"`                    // 驱动名称,默认为 "mysql"。
	ServerVersion                 string         `json:"serverVersion,omitempty"`       // 服务器版本,默认为空。
	DSN                           string         `json:"dsn,omitempty"`                 // DSN 字符串,默认为空。
	DSNConfig                     *mysqld.Config `json:"-"`                             // DSN 配置
	Conn                          gorm.ConnPool  `json:"connPool,omitempty"`            // 连接池,默认为空。
	SkipInitializeWithVersion     bool           `json:"skipInitializeWithVersion"`     // 跳过与版本号相关的初始化,默认为 false。
	DefaultStringSize             uint           `json:"defaultStringSize"`             // 字符串的默认长度,默认为 0。
	DefaultDatetimePrecision      *int           `json:"defaultDatetimePrecision"`      // 日期时间的默认精度,默认为 nil。
	DisableWithReturning          bool           `json:"disableWithReturning"`          // 禁用 WITH RETURNING,默认为 false。
	DisableDatetimePrecision      bool           `json:"disableDatetimePrecision"`      // 禁用日期时间精度,默认为 false。
	DontSupportRenameIndex        bool           `json:"dontSupportRenameIndex"`        // 不支持重命名索引,默认为 false。
	DontSupportRenameColumn       bool           `json:"dontSupportRenameColumn"`       // 不支持重命名列,默认为 false。
	DontSupportForShareClause     bool           `json:"dontSupportForShareClause"`     // 不支持 FOR SHARE 子句,默认为 false。
	DontSupportNullAsDefaultValue bool           `json:"dontSupportNullAsDefaultValue"` // 不支持 NULL 作为默认值,默认为 false。
	DontSupportRenameColumnUnique bool           `json:"dontSupportRenameColumnUnique"` // 不支持重命名列的唯一性约束,默认为 false。
	// As of MySQL 8.0.19, ALTER TABLE permits more general (and SQL standard) syntax
	// for dropping and altering existing constraints of any type.
	// see https://dev.mysql.com/doc/refman/8.0/en/alter-table.html
	DontSupportDropConstraint bool        `json:"dontSupportDropConstraint"` // 不支持使用 DROP CONSTRAINT 语法来删除约束,默认为 false。
	SSH                       *ssh.Config `json:"ssh,omitempty"`             // SSH 配置选项,默认为 nil。
}

Config 定义 MySQL 数据库驱动程序的配置选项。

Jump to

Keyboard shortcuts

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