Documentation ¶
Index ¶
- Constants
- func NewDefaultConn()
- type DeletedAt
- type Model
- type OptionFunc
- func ConnParams(activeNum int, idleNum int, idleExpire timeEx.Duration) OptionFunc
- func DSN(dsn string) OptionFunc
- func DebugMode(active bool) OptionFunc
- func Dialect(dialect string) OptionFunc
- func SingularTable(active bool) OptionFunc
- func TableFields(createdAt string, updatedAt string, deletedAt string, isDeleted string) OptionFunc
- type Options
- type SqlBuilderMixin
- type StatusModel
- type TemplateModel
- type TxModel
- type UserModel
- type UserUniqueModel
Constants ¶
View Source
const ( // // db type: // MySQL = "mysql" SQLite = "sqlite3" TiDB = "mysql" // // default options: // DefaultDialect = MySQL DefaultActiveNum = 20 // 连接数 max DefaultIdleNum = 10 // 连接数 max DefaultIdleExpire = "4h" // 超时 max DefaultQueryExpire = "5s" // 查询超时 DefaultExecExpire = "5s" // 写入超时 DefaultTxExpire = "5s" // tx 事务超时 )
View Source
const ( // // timestamp类型取值范围:1970-01-01 00:00:00 到 2037-12-31 23:59:59, // 初始值调整为: [1970-01-02 00:00:00 , 1970-01-01 00:00:01], 自定义零值, > 1970-01-01 00:00:00, 即可 // https://reading.developerlearning.cn/discuss/2019-06-19-gorm-mysql-timestamp/ MySqlZeroTimestamp = "1970-01-02 00:00:00" // 时间戳零值, 特殊值(MySQL) )
Variables ¶
This section is empty.
Functions ¶
func NewDefaultConn ¶
func NewDefaultConn()
Types ¶
type DeletedAt ¶
软删除类型:
func (DeletedAt) QueryClauses ¶
软删除-查询子句:(修正 判空条件)
- 自动补全
- where (deleted_at <= "1970-01-02 00:00:00" )
type Model ¶
type Model struct { SqlBuilderMixin // gen sql: ID uint64 `` /* 163-byte string literal not displayed */ CreatedAt time.Time `` /* 163-byte string literal not displayed */ UpdatedAt time.Time `` /* 163-byte string literal not displayed */ DeletedAt DeletedAt `` // 删除默认时间戳 /* 163-byte string literal not displayed */ }
type OptionFunc ¶
type OptionFunc func(*Options)
fn:
func ConnParams ¶
func ConnParams(activeNum int, idleNum int, idleExpire timeEx.Duration) OptionFunc
连接参数定制:
func DSN ¶
func DSN(dsn string) OptionFunc
func Dialect ¶
func Dialect(dialect string) OptionFunc
func TableFields ¶
func TableFields(createdAt string, updatedAt string, deletedAt string, isDeleted string) OptionFunc
表默认字段:
type Options ¶
type Options struct { Dialect string DSN string // data source name. ActiveNum int // pool IdleNum int // pool IdleTimeout timeEx.Duration // connect max life time. // option for table: IsSingularTable bool // db 表名: 单数/复数 IsDebugMode bool // log switch: show raw sql // option item: CreatedTsName string UpdatedTsName string DeletedTsName string IsDeletedName string }
db conn option:
func NewOptions ¶
func NewOptions(opts ...OptionFunc) Options
type SqlBuilderMixin ¶
type SqlBuilderMixin struct {
// contains filtered or unexported fields
}
gen sql:
func (*SqlBuilderMixin) ToSelectFields ¶
func (m *SqlBuilderMixin) ToSelectFields(model interface{}) string
model: 传数据实体的类型
type StatusModel ¶
type StatusModel struct { SqlBuilderMixin // gen sql: ID uint64 `` /* 163-byte string literal not displayed */ Status int64 `` /* 230-byte string literal not displayed */ CreatedAt time.Time `` /* 163-byte string literal not displayed */ UpdatedAt time.Time `` /* 163-byte string literal not displayed */ DeletedAt DeletedAt `` // 删除默认时间戳 /* 163-byte string literal not displayed */ }
has status:
type TemplateModel ¶
type TemplateModel struct { SqlBuilderMixin // gen sql: ID uint64 `` /* 163-byte string literal not displayed */ Ver uint64 `` // 乐观锁 /* 169-byte string literal not displayed */ CreatedAt time.Time `` /* 163-byte string literal not displayed */ UpdatedAt time.Time `` /* 163-byte string literal not displayed */ DeletedAt DeletedAt `` /* 163-byte string literal not displayed */ // Name string `db:"name" gorm:"type=varchar(128) CHARACTER SET utf8mb4; NOT NULL; DEFAULT:''; COMMENT:'姓名'; "` BankCardNo int64 `db:"bank_card_no" gorm:"type=int(11); NOT NULL; DEFAULT:''; COMMENT:'银行卡号'; "` }
集大成者:
type TxModel ¶
type TxModel struct { SqlBuilderMixin // gen sql: ID uint64 `` /* 163-byte string literal not displayed */ Ver uint64 `` // 乐观锁 /* 169-byte string literal not displayed */ CreatedAt time.Time `` /* 163-byte string literal not displayed */ UpdatedAt time.Time `` /* 163-byte string literal not displayed */ DeletedAt DeletedAt `` /* 163-byte string literal not displayed */ }
db 事务: 乐观锁
type UserModel ¶
type UserModel struct { SqlBuilderMixin // gen sql: ID uint64 `` /* 163-byte string literal not displayed */ UserID uint64 `` // 用户 ID /* 160-byte string literal not displayed */ CreatedAt time.Time `` /* 163-byte string literal not displayed */ UpdatedAt time.Time `` /* 163-byte string literal not displayed */ DeletedAt DeletedAt `` /* 163-byte string literal not displayed */ }
user model:
type UserUniqueModel ¶
type UserUniqueModel struct { SqlBuilderMixin // gen sql: ID uint64 `` /* 163-byte string literal not displayed */ UserID uint64 `` // 用户 ID /* 160-byte string literal not displayed */ CreatedAt time.Time `` /* 163-byte string literal not displayed */ UpdatedAt time.Time `` /* 163-byte string literal not displayed */ DeletedAt DeletedAt `` /* 163-byte string literal not displayed */ }
唯一索引:
Source Files ¶
Click to show internal directories.
Click to hide internal directories.