Documentation
¶
Index ¶
- Variables
- type Dbbase
- func (c *Dbbase) Connect(dialector *gorm.Dialector) (*gorm.DB, error)
- func (this *Dbbase) Dsn() string
- func (Dbbase) GormDBDataType(db *gorm.DB, field *schema.Field) string
- func (this Dbbase) GormDataType() string
- func (this *Dbbase) RemovePasswd()
- func (this *Dbbase) Scan(val interface{}) error
- func (this *Dbbase) SetInfo(args ...any)
- func (this Dbbase) Value() (driver.Value, error)
- type PostgresOpt
- type SoftDeleteModel
- type TableBaseModel
- type TableBaseModelAutoIncrement
- type TableBaseModelFull
- type TableDefaultCreateField
- type TableDefaultField
- type TableDefaultTimeField
- type TableDefaultUserField
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // SupportedDbType 支持的数据库类型 SupportedDbType = []map[string]string{ {"type": config.DbTypeMysql, "value": config.DbTypeMysql}, {"type": config.DbTypePg, "value": config.DbTypePostgres}, {"type": config.DbClientEs, "value": config.DbClientEs}, {"type": config.QueueTypeKafka, "value": config.QueueTypeKafka}, {"type": config.FileTypeFtp, "value": config.FileTypeFtp}, {"type": config.FileTypeSftp, "value": config.FileTypeSftp}, } // FTPEpsv ftp模式 FTPEpsv = []map[string]any{ {"type": 0, "value": "被动模式"}, {"type": 1, "value": "主动模式"}, } // Authentication 认证方式 Authentication = []map[string]string{ {"type": "password", "value": "密码"}, {"type": "public_key", "value": "密钥"}, } )
Functions ¶
This section is empty.
Types ¶
type Dbbase ¶
type Dbbase struct {
DbIdentifier string `` /* 144-byte string literal not displayed */
DbType string `` // 数据库类型 mysql/pg
/* 127-byte string literal not displayed */
// 这部分是公用的
Host dataType.StringArray `ini:"host" yaml:"host" json:"host,omitempty" gorm:"not null;comment:连接信息"`
User string `ini:"user" yaml:"user" json:"user,omitempty" gorm:"type:varchar(256);not null;default:'';comment:数据库用户"`
Pwd string `ini:"pwd" yaml:"pwd" json:"pwd,omitempty" gorm:"type:text;comment:数据库密码"`
// 这部分是数据库独有
Dbname string `` /* 128-byte string literal not displayed */
Schema string `ini:"schema" yaml:"schema" json:"schema,omitempty" gorm:"type:varchar(128);not null;default:'';comment:数据库模式"`
MaxIdleConns int `` /* 139-byte string literal not displayed */
MaxOpenConns int `` /* 134-byte string literal not displayed */
MaxConnLifetime time.Duration `` // DB服务器wait_timeout的80-90%
/* 151-byte string literal not displayed */
MaxConnIdleTime time.Duration `` // 平均请求间隔 × 3
/* 154-byte string literal not displayed */
TablePrefix string `` /* 130-byte string literal not displayed */
SingularTable int `` // 1 启用 0 不启用
/* 139-byte string literal not displayed */
PostgresOpt *PostgresOpt `json:"postgres_opt" yaml:"postgres_opt" json:"postgres_opt,omitempty" gorm:"comment:Postgres专属配置"`
Timeout int `ini:"timeout" yaml:"timeout" json:"timeout,omitempty" gorm:"type:int;not null;default:0;comment:sqlite 超时,单位毫秒"` // sqlite可用
Logger zaploger.Config `json:"logger" yaml:"logger" ini:"logger" gorm:"comment:日志配置"`
}
func (Dbbase) GormDBDataType ¶
func (Dbbase) GormDataType ¶
func (*Dbbase) RemovePasswd ¶
func (this *Dbbase) RemovePasswd()
type PostgresOpt ¶
type PostgresOpt struct {
Passfile string `ini:"passfile" yaml:"passfile" json:"passfile,omitempty"` // 密码文件路径
ConnectTimeout string `ini:"connect_timeout" yaml:"connect_timeout" json:"connect_timeout,omitempty"` // 连接超时(秒)
ClientEncoding string `ini:"client_encoding" yaml:"client_encoding" json:"client_encoding,omitempty"` // 客户端编码
//连接行为参数
Sslmode string `ini:"sslmode" yaml:"sslmode" json:"sslmode,omitempty"` // SSL模式(disable|allow|prefer|require|verify-ca|verify-full)
Sslcompression string `ini:"sslcompression" yaml:"sslcompression" json:"sslcompression,omitempty"` // SSL压缩(0/1)
Sslcert string `ini:"sslcert" yaml:"sslcert" json:"sslcert,omitempty"` // SSL客户端证书路径
Sslkey string `ini:"sslkey" yaml:"sslkey" json:"sslkey,omitempty"` // SSL客户端密钥路径
Sslrootcert string `ini:"sslrootcert" yaml:"sslrootcert" json:"sslrootcert,omitempty"` // SSL根证书路径
Sslcrl string `ini:"sslcrl" yaml:"sslcrl" json:"sslcrl,omitempty"` // SSL证书撤销列表路径
Sslpassword string `ini:"sslpassword" yaml:"sslpassword" json:"sslpassword,omitempty"` // SSL密钥密码
Service string `ini:"service" yaml:"service" json:"service,omitempty"` // 服务名(用于pg_service.conf)
TargetSessionAttrs string `ini:"target_session_attrs" yaml:"target_session_attrs" json:"target_session_attrs,omitempty"` // 目标会话属性(read-write|primary)
//应用行为参数
ApplicationName string `ini:"application_name" yaml:"application_name" json:"application_name,omitempty"` // 应用名称
FallbackApplicationName string `ini:"fallback_application_name" yaml:"fallback_application_name" json:"fallback_application_name,omitempty"` // 备用应用名称
Keepalives string `ini:"keepalives" yaml:"keepalives" json:"keepalives,omitempty"` // 是否启用TCP保持连接(1/0)
KeepalivesIdle string `ini:"keepalives_idle" yaml:"keepalives_idle" json:"keepalives_idle,omitempty"` // TCP保持连接空闲时间(秒)
KeepalivesInterval string `ini:"keepalives_interval" yaml:"keepalives_interval" json:"keepalives_interval,omitempty"` // TCP保持连接间隔(秒)
KeepalivesCount string `ini:"keepalives_count" yaml:"keepalives_count" json:"keepalives_count,omitempty"` // TCP保持连接探测次数
TcpUserTimeout string `ini:"tcp_user_timeout" yaml:"tcp_user_timeout" json:"tcp_user_timeout,omitempty"` // TCP用户超时(毫秒)
// 性能参数
StatementCacheMode string `ini:"statement_cache_mode" yaml:"statement_cache_mode" json:"statement_cache_mode,omitempty"` // 语句缓存模式
StatementCacheSize string `ini:"statement_cache_size" yaml:"statement_cache_size" json:"statement_cache_size,omitempty"` //语句缓存大小
PreferSimpleProtocol string `ini:"prefer_simple_protocol" yaml:"prefer_simple_protocol" json:"prefer_simple_protocol,omitempty"` //偏好简单协议(布尔)
}
func (PostgresOpt) GormDBDataType ¶
func (PostgresOpt) GormDataType ¶
func (d PostgresOpt) GormDataType() string
func (*PostgresOpt) Scan ¶
func (d *PostgresOpt) Scan(val interface{}) error
type SoftDeleteModel ¶
type SoftDeleteModel struct {
IsDeleted dataType.Bool `json:"is_deleted,omitempty" gorm:"not null;index;default:(0);comment:软删除标记 0 正常 1 删除" form:"is_deleted"`
DeletedBy dataType.IntString[int64] `json:"deleted_by,omitempty" gorm:"comment:删除人ID" form:"deleted_by"`
DeletedTime *dataType.CustomTime `json:"deleted_time,omitempty" gorm:"index;comment:删除时间" form:"-"`
}
SoftDeleteModel 带软删除的通用表结构
type TableBaseModel ¶
type TableBaseModel struct {
// 注意,这个ID字段不是自增的,
Id dataType.IntString[int64] `json:"id,omitempty" gorm:"primaryKey;autoIncrement:false;comment:行ID" form:"id"`
CreateTime *dataType.CustomTime `` /* 132-byte string literal not displayed */
CreateBy dataType.IntString[int64] `json:"create_by,omitempty" gorm:"comment:创建人ID" form:"create_by"`
}
TableBaseModel 带创建人信息、创建时间、的通用表结构
type TableBaseModelAutoIncrement ¶
type TableBaseModelAutoIncrement struct {
Id dataType.IntString[int64] `json:"id,omitempty" gorm:"primaryKey;autoIncrement;comment:行ID" form:"id"`
CreateTime *dataType.CustomTime `` /* 132-byte string literal not displayed */
CreateBy dataType.IntString[int64] `json:"create_by,omitempty" gorm:"comment:创建人ID" form:"create_by"`
UpdateTime *dataType.CustomTime `json:"update_time,omitempty" gorm:"autoUpdateTime:true;comment:记录更新时间" form:"-"`
UpdateBy dataType.IntString[int64] `json:"update_by,omitempty" gorm:"comment:更新人ID" form:"update_by"`
}
type TableBaseModelFull ¶
type TableBaseModelFull struct {
// 注意,这个ID字段不是自增的,
Id dataType.IntString[int64] `json:"id,omitempty" gorm:"primaryKey;autoIncrement:false;comment:行ID" form:"id"`
CreateTime *dataType.CustomTime `` /* 132-byte string literal not displayed */
CreateBy dataType.IntString[int64] `json:"create_by,omitempty" gorm:"comment:创建人ID" form:"create_by"`
UpdateTime *dataType.CustomTime `json:"update_time,omitempty" gorm:"autoUpdateTime:true;comment:记录更新时间" form:"-"`
UpdateBy dataType.IntString[int64] `json:"update_by,omitempty" gorm:"comment:更新人ID" form:"update_by"`
}
TableBaseModelFull 带全字段的通用表结构 包含主键、创建人信息、创建时间、更新时间、更新人信息
type TableDefaultCreateField ¶
type TableDefaultCreateField struct {
Id int `json:"id,omitempty" gorm:"primaryKey;not null;autoIncrement;comment:行ID" form:"id"`
CreateTime dataType.CustomTime `` /* 132-byte string literal not displayed */
}
type TableDefaultField ¶
type TableDefaultField struct {
Id int `json:"id,omitempty" gorm:"primaryKey;not null;autoIncrement;comment:行ID" form:"id"`
CreateTime dataType.CustomTime `` /* 132-byte string literal not displayed */
UpdateTime dataType.CustomTime `json:"update_time,omitempty" gorm:"autoUpdateTime:true;index;comment:记录更新时间" form:"-"`
}
TableDefaultField 用于快速定义默认的表结构字段,包含id 创建时间 更新时间
type TableDefaultTimeField ¶
type TableDefaultTimeField struct {
CreateTime dataType.CustomTime `` /* 132-byte string literal not displayed */
UpdateTime dataType.CustomTime `json:"update_time,omitempty" gorm:"autoUpdateTime:true;index;comment:记录更新时间" form:"-"`
}
TableDefaultTimeField 用于快速定义默认的表结构时间字段,这里不需要定义字段类型,因为会自动根据字段类型进行转换
type TableDefaultUserField ¶
type TableDefaultUserField struct {
Id int `json:"id,omitempty" gorm:"primaryKey;not null;autoIncrement;comment:行ID" form:"id"`
CreateUserId int `json:"create_user_id,omitempty" gorm:"not null;default:0;index;comment:创建人ID" form:"create_user_id"`
CreateUserName string `` /* 126-byte string literal not displayed */
CreateTime dataType.CustomTime `` /* 132-byte string literal not displayed */
UpdateTime dataType.CustomTime `json:"update_time,omitempty" gorm:"autoUpdateTime:true;index;comment:记录更新时间" form:"-"`
}
TableDefaultUserField 用于快速定义默认的表结构用户字段,包含id 用户信息字段 创建时间 更新时间
Click to show internal directories.
Click to hide internal directories.