Documentation
¶
Index ¶
- Variables
- func IsDuplicatedKey(err error) bool
- func IsForeignKeyViolated(err error) bool
- func IsRecordNotFound(err error) bool
- func NewLogger(config LoggerConfig) logger.Interface
- func Register(name string, driver Driver)
- type DB
- type DialectorFunc
- type Driver
- type Expr
- type Locking
- type LoggerConfig
- type Metadata
- type OnConflict
- type Option
- type PoolConfig
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrDriverRequired = errx.New("database driver is required") ErrDSNRequired = errx.New("database dsn is required") ErrDriverNotRegistered = errx.New("database driver is not registered") // ErrRecordNotFound 表示查询没有找到记录。 ErrRecordNotFound = gorm.ErrRecordNotFound // ErrDuplicatedKey 表示唯一约束或主键冲突。 ErrDuplicatedKey = gorm.ErrDuplicatedKey // ErrForeignKeyViolated 表示外键约束冲突。 ErrForeignKeyViolated = gorm.ErrForeignKeyViolated )
Functions ¶
func IsForeignKeyViolated ¶
IsForeignKeyViolated 判断错误链是否包含外键约束错误。
func NewLogger ¶
func NewLogger(config LoggerConfig) logger.Interface
NewLogger 创建从 GORM context 读取 core/logx Logger 的日志适配器。
Types ¶
type DialectorFunc ¶
DialectorFunc 根据原生 DSN 创建 GORM Dialector。
type Driver ¶
type Driver struct {
Dialector DialectorFunc
Pool PoolConfig
}
Driver 描述按需注册的数据库驱动及其默认连接池参数。
type LoggerConfig ¶
type LoggerConfig struct {
SlowThreshold time.Duration
LogLevel logger.LogLevel
IgnoreRecordNotFoundError bool
}
LoggerConfig 定义 GORM 日志级别和慢查询阈值。
func DefaultLoggerConfig ¶
func DefaultLoggerConfig() LoggerConfig
DefaultLoggerConfig 返回与 core/logx 默认级别一致的 GORM 日志配置。
type Metadata ¶
type Metadata struct {
// Id 主键
Id string `json:"id" gorm:"primaryKey;comment:主键"`
// 创建人
CreatedBy string `json:"created_by" gorm:"type:varchar(36);comment:创建人"`
// 创建时间
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime:milli;comment:创建时间"`
// 更新人
UpdatedBy string `json:"updated_by" gorm:"type:varchar(36);comment:更新人"`
// 更新时间
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime:milli;comment:更新时间"`
// 删除时间,0 表示有效记录,非 0 值为 Unix 毫秒时间戳
DeletedAt datatype.DeletedAt `json:"deleted_at" gorm:"not null;default:0;index;comment:删除时间"`
}
Metadata 元数据
type Option ¶
type Option func(*config)
Option 调整 Open 的公共配置。
func WithGORMConfig ¶
WithGORMConfig 使用指定的 GORM 配置覆盖默认配置;TranslateError 始终保持开启。
func WithGORMOptions ¶
WithGORMOptions 追加传递给 gorm.Open 的选项。
Directories
¶
| Path | Synopsis |
|---|---|
|
Package migrate 提供带跨副本锁的有序 GORM 数据库迁移。
|
Package migrate 提供带跨副本锁的有序 GORM 数据库迁移。 |
|
Package mysql 按需注册 MySQL GORM 驱动。
|
Package mysql 按需注册 MySQL GORM 驱动。 |
|
Package postgres 按需注册 PostgreSQL GORM 驱动。
|
Package postgres 按需注册 PostgreSQL GORM 驱动。 |
|
Package sqlite 按需注册无 CGO 的 SQLite GORM 驱动。
|
Package sqlite 按需注册无 CGO 的 SQLite GORM 驱动。 |
Click to show internal directories.
Click to hide internal directories.