orm

package
v0.1.147 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(config map[string]interface{}) (interface{}, error)

Types

type Client

type Client struct {
	Db *gorm.DB
	// contains filtered or unexported fields
}

func (*Client) Init

func (c *Client) Init() error

func (*Client) LogLevel

func (c *Client) LogLevel() logger.LogLevel

func (*Client) SetAllowGlobalUpdate

func (c *Client) SetAllowGlobalUpdate(v bool)

启用全局 update/delete,查看 Session 获取详情

func (*Client) SetDefaultStringSize

func (c *Client) SetDefaultStringSize(v uint)

string 类型字段的默认长度

func (*Client) SetDialect

func (c *Client) SetDialect(v IFuncDialect)

设置数据库对象

func (*Client) SetDisableAutomaticPing

func (c *Client) SetDisableAutomaticPing(v bool)

在完成初始化后,GORM 会自动 ping 数据库以检查数据库的可用性,若要禁用该特性,可将其设置为 true

func (*Client) SetDisableDatetimePrecision

func (c *Client) SetDisableDatetimePrecision(v bool)

禁用 datetime 精度,MySQL 5.6 之前的数据库不支持

func (*Client) SetDisableForeignKeyConstraintWhenMigrating

func (c *Client) SetDisableForeignKeyConstraintWhenMigrating(v bool)

在 AutoMigrate 或 CreateTable 时,GORM 会自动创建外键约束,若要禁用该特性,可将其设置为 true,参考 迁移 获取详情。

func (*Client) SetDontSupportRenameColumn

func (c *Client) SetDontSupportRenameColumn(v bool)

用 `change` 重命名列,MySQL 8 之前的数据库和 MariaDB 不支持重命名列

func (*Client) SetDontSupportRenameIndex

func (c *Client) SetDontSupportRenameIndex(v bool)

重命名索引时采用删除并新建的方式,MySQL 5.7 之前的数据库和 MariaDB 不支持重命名索引

func (*Client) SetDriver

func (c *Client) SetDriver(driver string)

SetDriver set driver db use, eg. "mysql"

func (*Client) SetDryRun

func (c *Client) SetDryRun(v bool)

生成 SQL 但不执行,可以用于准备或测试生成的 SQL,参考 会话 获取详情

func (*Client) SetDsn

func (c *Client) SetDsn(dsn string)

SetDsn set master dsn, the dsn is driver specified, eg. dsn format for github.com/go-sql-driver/mysql is [username[:password]@][protocol[(address)]]/dbname[?param=value]

func (*Client) SetLogLevel

func (c *Client) SetLogLevel(v logger.LogLevel)

func (*Client) SetMaxConnTime

func (c *Client) SetMaxConnTime(v string) error

SetMaxConnTime set conn life time, default is 1h

func (*Client) SetMaxIdleConn

func (c *Client) SetMaxIdleConn(maxIdleConn int)

SetMaxIdleConn set max idle conn, default is 5

func (*Client) SetMaxOpenConn

func (c *Client) SetMaxOpenConn(maxOpenConn int)

SetMaxOpenConn set max open conn, default is 0

func (*Client) SetPrepareStmt

func (c *Client) SetPrepareStmt(v bool)

SetPrepareStmt 执行任何 SQL 时都创建并缓存预编译语句,可以提高后续的调用速度

func (*Client) SetSingularTable

func (c *Client) SetSingularTable(v bool)

使用单数表名,启用该选项

func (*Client) SetSkipDefaultTransaction

func (c *Client) SetSkipDefaultTransaction(v bool)

SetSkipDefaultTransaction 对于写操作(创建、更新、删除),为了确保数据的完整性,GORM 会将它们封装在事务内运行。但这会降低性能,你可以在初始化时禁用这种方式

func (*Client) SetSkipInitializeWithVersion

func (c *Client) SetSkipInitializeWithVersion(v bool)

根据当前 MySQL 版本自动配置

func (*Client) SetSlaves

func (c *Client) SetSlaves(v []interface{})

SetSlaves set dsn for slaves

func (*Client) SetSlowLogTime

func (c *Client) SetSlowLogTime(v string) error

SetSlowTime set slow log time, default is 100ms

func (*Client) SetSqlLog

func (c *Client) SetSqlLog(sqlLog bool)

func (*Client) SetTablePrefix

func (c *Client) SetTablePrefix(v string)

表名前缀,`User` 的表名应该是 v+`_user`

func (*Client) SlowLogTime

func (c *Client) SlowLogTime() time.Duration

func (*Client) SqlLog

func (c *Client) SqlLog() bool

type IFuncDialect

type IFuncDialect func(dsn string) gorm.Dialector

Jump to

Keyboard shortcuts

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