Documentation
¶
Index ¶
- Constants
- func Close()
- func Connect(addr, user, pwd, dbName string, options ...Option)
- func DB(ctx context.Context) *gorm.DB
- func IsRecordNotFoundErr(err error) bool
- func StartTransaction(ctx context.Context, trans TransactionFunc) error
- type Option
- func WithConnTimeout(timeout int) Option
- func WithIgnoreRecordNotFoundError(ignoreRecordNotFoundError bool) Option
- func WithParameterizedQueries(parameterizedQueries bool) Option
- func WithSSLMode(sslMode string) Option
- func WithSilent(silent bool) Option
- func WithSlowThreshold(slowThreshold time.Duration) Option
- func WithTimeZone(timeZone string) Option
- type Options
- type TransactionFunc
Constants ¶
View Source
const ( DefaultSlowThreshold = time.Second DefaultSingularTable = true )
Variables ¶
This section is empty.
Functions ¶
func StartTransaction ¶
func StartTransaction(ctx context.Context, trans TransactionFunc) error
StartTransaction 开启事务
Types ¶
type Option ¶
type Option func(*Options)
func WithConnTimeout ¶ added in v1.4.0
WithConnTimeout 设置连接超时时间(秒)
func WithIgnoreRecordNotFoundError ¶
WithIgnoreRecordNotFoundError 忽略记录不存在错误
func WithParameterizedQueries ¶
WithParameterizedQueries 使用参数化查询
func WithSSLMode ¶ added in v1.4.0
WithSSLMode 设置 SSL 模式("disable", "require", "verify-ca", "verify-full")
func WithSlowThreshold ¶
WithSlowThreshold 设置慢查询阈值
func WithTimeZone ¶ added in v1.4.0
WithTimeZone 设置时区(例如:"UTC", "Asia/Shanghai", "America/New_York")
type Options ¶
type Options struct {
TablePrefix string // 表前缀
SingularTable bool // 使用单数表名
// Logger
Silent bool // 是否打印 sql 语句
ParameterizedQueries bool // 使用参数化查询
IgnoreRecordNotFoundError bool // 忽略记录不存在错误
SlowThreshold time.Duration // 慢查询阈值
// Connection
TimeZone string // 时区配置,默认 "UTC"
SSLMode string // SSL 模式,默认 "disable"
ConnTimeout int // 连接超时时间(秒),默认 10
}
type TransactionFunc ¶
Click to show internal directories.
Click to hide internal directories.