You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
860 B
Go
37 lines
860 B
Go
package model
|
|
|
|
import (
|
|
"database/sql/driver"
|
|
"errors"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
var ErrNotFound = gorm.ErrRecordNotFound
|
|
|
|
const VersionRetryCount = 10 // 乐观锁重试次数
|
|
|
|
// BitBool is an implementation of a bool for the MySQL type BIT(1).
|
|
// This type allows you to avoid wasting an entire byte for MySQL's boolean type TINYINT.
|
|
type BitBool bool
|
|
|
|
// Value implements the driver.Valuer interface,
|
|
// and turns the BitBool into a bitfield (BIT(1)) for MySQL storage.
|
|
func (b BitBool) Value() (driver.Value, error) {
|
|
if b {
|
|
return []byte{1}, nil
|
|
} else {
|
|
return []byte{0}, nil
|
|
}
|
|
}
|
|
|
|
// Scan implements the sql.Scanner interface,
|
|
// and turns the bitfield incoming from MySQL into a BitBool
|
|
func (b *BitBool) Scan(src interface{}) error {
|
|
v, ok := src.([]byte)
|
|
if !ok {
|
|
return errors.New("bad []byte type assertion")
|
|
}
|
|
*b = v[0] == 1
|
|
return nil
|
|
}
|