dataType

package
v2.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlobDbDataType

func BlobDbDataType(db *gorm.DB, _ *schema.Field) string

func CheckVersionSupportsJSON

func CheckVersionSupportsJSON(versionStr string) bool

CheckVersionSupportsJSON 检查版本是否支持JSON mysql版本高于 5.7.8 ,才支持json

func DriverScanWithInt

func DriverScanWithInt[T constraints.Integer](val any, dst *T) error

func DriverScanWithJson

func DriverScanWithJson[T any](val any, dst *T) error

DriverScanWithJson 解析json

func DriverValueWithJson

func DriverValueWithJson(val any) (driver.Value, error)

func HelperStringGormDBDataType

func HelperStringGormDBDataType(db *gorm.DB, field *schema.Field, length int) string

func HelperStringScan

func HelperStringScan[T ~string](val any, dst *T) error

HelperStringScan 通用的 string 自定义类型 SCAN函数

func JsonDbDataType

func JsonDbDataType(db *gorm.DB, _ *schema.Field) string

func MapGormValue

func MapGormValue(data string, db *gorm.DB) clause.Expr

MapGormValue 下面的操作是借鉴的 https://github.com/go-gorm/datatypes/blob/master/json_map.go#L94

Types

type AnyArray

type AnyArray[T any] []T

AnyArray 泛型版本的数组

func (AnyArray[T]) GormDBDataType

func (AnyArray[T]) GormDBDataType(db *gorm.DB, field *schema.Field) string

noinspection all

func (AnyArray[T]) GormValue

func (a AnyArray[T]) GormValue(ctx context.Context, db *gorm.DB) clause.Expr

noinspection all

func (*AnyArray[T]) Scan

func (a *AnyArray[T]) Scan(val interface{}) error

noinspection all

func (AnyArray[T]) Value

func (a AnyArray[T]) Value() (driver.Value, error)

noinspection all

type Array

type Array []any

func (Array) GormDBDataType

func (Array) GormDBDataType(db *gorm.DB, field *schema.Field) string

GormDBDataType gorm db data type noinspection all

func (Array) GormValue

func (jm Array) GormValue(ctx context.Context, db *gorm.DB) clause.Expr

noinspection all

func (*Array) Scan

func (m *Array) Scan(val interface{}) error

Scan scan value into Jsonb, implements sql.Scanner interface noinspection all

func (Array) Value

func (m Array) Value() (driver.Value, error)

Value return json value, implement driver.Valuer interface noinspection all

type Binary

type Binary []byte

func (Binary) GormDBDataType

func (Binary) GormDBDataType(db *gorm.DB, field *schema.Field) string

GormDBDataType 返回数据库特定的数据类型名称 noinspection all

func (*Binary) Scan

func (bf *Binary) Scan(value interface{}) error

Scan 实现了 sql.Scanner 接口,用于从数据库读取二进制数据到 BinaryFile 类型 noinspection all

func (Binary) Value

func (bf Binary) Value() (driver.Value, error)

Value 实现了 driver.Valuer 接口,用于将 BinaryFile 类型的数据写入数据库 noinspection all

type Bool

type Bool struct {
	// contains filtered or unexported fields
}

Bool 注意当使用这个类型时,在定义模型时,默认值需要带上括号。不然pg数据库会报错。

func NewBool

func NewBool(b bool) Bool

func (Bool) Bool

func (b Bool) Bool() bool

noinspection all

func (*Bool) Equals

func (b *Bool) Equals(b2 Bool) bool

func (*Bool) GobDecode

func (b *Bool) GobDecode(data []byte) error

func (Bool) GobEncode

func (b Bool) GobEncode() ([]byte, error)

func (Bool) GormDBDataType

func (Bool) GormDBDataType(db *gorm.DB, _ *schema.Field) string

noinspection all

func (Bool) GormDataType

func (b Bool) GormDataType() string

noinspection all

func (Bool) Int

func (b Bool) Int() int

noinspection all

func (Bool) MarshalJSON

func (b Bool) MarshalJSON() ([]byte, error)

func (*Bool) Resverse

func (b *Bool) Resverse()

Resverse 反转 noinspection all

func (*Bool) Scan

func (b *Bool) Scan(value any) error

noinspection all

func (*Bool) Set

func (b *Bool) Set(b2 Bool)

func (*Bool) SetBool

func (b *Bool) SetBool(b2 bool)

func (*Bool) SetInt

func (b *Bool) SetInt(i int)

func (*Bool) SetString

func (b *Bool) SetString(s string)

func (*Bool) UnmarshalJSON

func (b *Bool) UnmarshalJSON(data []byte) error

func (Bool) Value

func (b Bool) Value() (driver.Value, error)

noinspection all

type Byte

type Byte byte

func (Byte) GormDBDataType

func (Byte) GormDBDataType(db *gorm.DB, field *schema.Field) string

noinspection all

func (*Byte) Scan

func (b *Byte) Scan(value any) error

noinspection all

func (Byte) Value

func (b Byte) Value() (driver.Value, error)

noinspection all

type ContentType

type ContentType int

ContentType 表示检测到的内容类型

const (
	Unknown ContentType = iota
	JSON
	PlainText
	CSV
	Excel
)

func DetectContentType

func DetectContentType(header http.Header) ContentType

DetectContentType 从 HTTP 请求头中检测内容类型

func (ContentType) Ext

func (ct ContentType) Ext() string

noinspection all

func (ContentType) GormDBDataType

func (ContentType) GormDBDataType(db *gorm.DB, field *schema.Field) string

noinspection all

func (*ContentType) Scan

func (ct *ContentType) Scan(val any) error

noinspection all

func (ContentType) String

func (ct ContentType) String() string

String 返回内容类型的字符串表示 noinspection all

func (ContentType) Value

func (ct ContentType) Value() (driver.Value, error)

noinspection all

type CustomDate

type CustomDate struct {
	time.Time
}

func (CustomDate) GormDBDataType

func (CustomDate) GormDBDataType(db *gorm.DB, field *schema.Field) string

noinspection all

func (CustomDate) GormDataType

func (c CustomDate) GormDataType() string

noinspection all

func (CustomDate) MarshalJSON

func (c CustomDate) MarshalJSON() ([]byte, error)

noinspection all

func (*CustomDate) Scan

func (c *CustomDate) Scan(value interface{}) (err error)

noinspection all

func (CustomDate) String

func (c CustomDate) String() string

noinspection all

func (*CustomDate) UnmarshalJSON

func (c *CustomDate) UnmarshalJSON(b []byte) (err error)

noinspection all

func (CustomDate) Value

func (c CustomDate) Value() (driver.Value, error)

noinspection all

type CustomTime

type CustomTime struct {
	time.Time
}

func NewCustomTime

func NewCustomTime(t time.Time) CustomTime

func NewCustomTimeNow

func NewCustomTimeNow() CustomTime

func (*CustomTime) AdjustTimezoneIfNeeded

func (c *CustomTime) AdjustTimezoneIfNeeded()

AdjustTimezoneIfNeeded 调整时区 noinspection all

func (CustomTime) GormDBDataType

func (CustomTime) GormDBDataType(db *gorm.DB, field *schema.Field) string

GormDBDataType gorm db data type noinspection all

func (CustomTime) GormDataType

func (c CustomTime) GormDataType() string

GormDataType 这个时间自定义字段,只能用time类型,不然当表中设置有 autoUpdateTime控制属性时会有问题。 使用Update方法,只有DataType是time的时候,才会生成time.Time类型, 其他类型都会转成时间戳。 noinspection all

func (CustomTime) IsZero

func (c CustomTime) IsZero() bool

noinspection all

func (CustomTime) MarshalJSON

func (c CustomTime) MarshalJSON() ([]byte, error)

MarshalJSON 序列化至json字符串 noinspection all

func (*CustomTime) Scan

func (c *CustomTime) Scan(value interface{}) (err error)

noinspection all

func (CustomTime) String

func (c CustomTime) String() string

noinspection all

func (CustomTime) ToPtr

func (c CustomTime) ToPtr() *CustomTime

noinspection all

func (CustomTime) ToTime

func (c CustomTime) ToTime() time.Time

noinspection all

func (*CustomTime) UnmarshalJSON

func (c *CustomTime) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON 反序列化 noinspection all

func (CustomTime) Value

func (c CustomTime) Value() (driver.Value, error)

noinspection all

type DynamicTime

type DynamicTime struct {
	time.Time
	Format string
}

func (DynamicTime) MarshalJSON

func (dt DynamicTime) MarshalJSON() ([]byte, error)

type IntString

type IntString[T constraints.Integer] struct {
	// contains filtered or unexported fields
}

func NewIntString

func NewIntString[T constraints.Integer](v T) IntString[T]

NewIntString 添加一些便利方法

func NewIntStringAsNumber

func NewIntStringAsNumber[T constraints.Integer](v T) IntString[T]

func StringToIntString

func StringToIntString[T constraints.Integer](v string) (IntString[T], error)

func ZeroIntString

func ZeroIntString[T constraints.Integer]() IntString[T]

ZeroIntString 零值(未设置值)

func (IntString[T]) Equals

func (i IntString[T]) Equals(other IntString[T]) bool

Equals 实现 Equals 方法用于比较 noinspection all

func (IntString[T]) GetJsonAsString

func (i IntString[T]) GetJsonAsString() bool

func (*IntString[T]) GetValid

func (i *IntString[T]) GetValid() bool

func (IntString[T]) GetValue

func (i IntString[T]) GetValue() T

noinspection all

func (*IntString[T]) GobDecode

func (i *IntString[T]) GobDecode(data []byte) error

noinspection all

func (IntString[T]) GobEncode

func (i IntString[T]) GobEncode() ([]byte, error)

GobEncode noinspection all

func (IntString[T]) GormDBDataType

func (i IntString[T]) GormDBDataType(db *gorm.DB, field *schema.Field) string

noinspection all

func (IntString[T]) IsValid

func (i IntString[T]) IsValid() bool

IsValid 检查值是否有效 noinspection all

func (IntString[T]) IsZero

func (i IntString[T]) IsZero() bool

IsZero 添加零值检查 noinspection all

func (IntString[T]) MarshalJSON

func (i IntString[T]) MarshalJSON() ([]byte, error)

noinspection all

func (*IntString[T]) Scan

func (i *IntString[T]) Scan(val any) error

noinspection all

func (*IntString[T]) SetJsonAsString

func (i *IntString[T]) SetJsonAsString(asString bool)

SetJsonAsString 或者使用方法设置 noinspection all

func (*IntString[T]) SetValue

func (i *IntString[T]) SetValue(v T)

noinspection all

func (IntString[T]) String

func (i IntString[T]) String() string

实现 Stringer 接口 noinspection all

func (*IntString[T]) UnmarshalJSON

func (i *IntString[T]) UnmarshalJSON(data []byte) error

noinspection all

func (*IntString[T]) UnmarshalText

func (i *IntString[T]) UnmarshalText(text []byte) error

UnmarshalText 实现 TextMarshaler 接口 这个主要是从query参数中进行提取,所以这里统一处理为字符串 noinspection all

func (IntString[T]) Value

func (i IntString[T]) Value() (driver.Value, error)

Value 注意,在写数据库的时候,貌似只支持 int64 noinspection all

type JSONMap

type JSONMap map[string]any

JSONMap defined JSON data type, need to implements driver.Valuer, sql.Scanner interface noinspection all

func (JSONMap) GormDBDataType

func (JSONMap) GormDBDataType(db *gorm.DB, field *schema.Field) string

GormDBDataType gorm db data type noinspection all

func (JSONMap) GormDataType

func (m JSONMap) GormDataType() string

GormDataType gorm common data type noinspection all

func (JSONMap) GormValue

func (jm JSONMap) GormValue(_ context.Context, db *gorm.DB) clause.Expr

noinspection all

func (JSONMap) MarshalJSON

func (m JSONMap) MarshalJSON() ([]byte, error)

MarshalJSON to output non base64 encoded []byte noinspection all

func (*JSONMap) Scan

func (m *JSONMap) Scan(val any) error

Scan scan value into Jsonb, implements sql.Scanner interface noinspection all

func (*JSONMap) UnmarshalJSON

func (m *JSONMap) UnmarshalJSON(b []byte) error

UnmarshalJSON to deserialize []byte 这个函数很重要,Scan的时候 序列化通用函数会用到这个 noinspection all

func (JSONMap) Value

func (m JSONMap) Value() (driver.Value, error)

Value return json value, implement driver.Valuer interface noinspection all

type JSONRaw

type JSONRaw json.RawMessage

func (JSONRaw) GormDBDataType

func (JSONRaw) GormDBDataType(db *gorm.DB, field *schema.Field) string

GormDBDataType gorm db data type noinspection all

func (JSONRaw) GormDataType

func (JSONRaw) GormDataType() string

GormDataType gorm common data type. noinspection all

func (JSONRaw) GormValue

func (js JSONRaw) GormValue(ctx context.Context, db *gorm.DB) clause.Expr

noinspection all

func (JSONRaw) MarshalJSON

func (js JSONRaw) MarshalJSON() ([]byte, error)

MarshalJSON to output non base64 encoded []byte noinspection all

func (*JSONRaw) Scan

func (j *JSONRaw) Scan(value interface{}) error

Scan value into Jsonb, implements sql.Scanner interface noinspection all

func (*JSONRaw) UnmarshalJSON

func (js *JSONRaw) UnmarshalJSON(b []byte) error

UnmarshalJSON to deserialize []byte noinspection all

func (JSONRaw) Value

func (j JSONRaw) Value() (driver.Value, error)

Value return json value, implement driver.Valuer interface noinspection all

type SessionValue

type SessionValue struct {
	Val any
}

noinspection all

func NewSessionValue

func NewSessionValue(val any) SessionValue

func (SessionValue) GormDBDataType

func (SessionValue) GormDBDataType(db *gorm.DB, field *schema.Field) string

GormDBDataType gorm db data type noinspection all

func (SessionValue) GormDataType

func (s SessionValue) GormDataType() string

func (*SessionValue) Scan

func (s *SessionValue) Scan(val any) error

noinspection all

func (SessionValue) Value

func (s SessionValue) Value() (driver.Value, error)

Value return blob value, implement driver.Valuer interface noinspection all

type String

type String string

func (String) GormDBDataType

func (String) GormDBDataType(db *gorm.DB, field *schema.Field) string

GormDBDataType gorm db data type noinspection all

func (String) GormDataType

func (s String) GormDataType() string

noinspection all

func (*String) Scan

func (s *String) Scan(val interface{}) (err error)

noinspection all

func (String) Value

func (s String) Value() (driver.Value, error)

noinspection all

type StringArray

type StringArray []string

func (StringArray) GormDBDataType

func (StringArray) GormDBDataType(db *gorm.DB, field *schema.Field) string

noinspection all

func (StringArray) GormValue

func (jm StringArray) GormValue(ctx context.Context, db *gorm.DB) clause.Expr

noinspection all

func (*StringArray) Scan

func (m *StringArray) Scan(val interface{}) error

noinspection all

func (StringArray) Value

func (m StringArray) Value() (driver.Value, error)

noinspection all

type Timestamp

type Timestamp struct {
	// contains filtered or unexported fields
}

func NewTimestamp

func NewTimestamp(t time.Time, formats ...string) *Timestamp

func (*Timestamp) Format

func (t *Timestamp) Format(layout string) string

Format 使用指定格式格式化时间 noinspection all

func (Timestamp) GormDBDataType

func (t Timestamp) GormDBDataType(db *gorm.DB, field *schema.Field) string

GormDBDataType gorm db data type noinspection all

func (Timestamp) GormDataType

func (t Timestamp) GormDataType() string

GormDataType gorm db data type noinspection all

func (*Timestamp) IsZero

func (t *Timestamp) IsZero() bool

IsZero 判断时间是否为零值 noinspection all

func (*Timestamp) MarshalJSON

func (t *Timestamp) MarshalJSON() ([]byte, error)

MarshalJSON 实现 JSON 序列化接口 noinspection all

func (*Timestamp) Scan

func (t *Timestamp) Scan(value interface{}) error

noinspection all

func (*Timestamp) SetFormat

func (t *Timestamp) SetFormat(format string)

SetFormat 设置格式化字符串 noinspection all

func (*Timestamp) SetTime

func (t *Timestamp) SetTime(time time.Time)

SetTime 设置时间 noinspection all

func (*Timestamp) String

func (t *Timestamp) String() string

String 实现 Stringer 接口 noinspection all

func (*Timestamp) Time

func (t *Timestamp) Time() time.Time

Time 返回内部的 time.Time noinspection all

func (*Timestamp) Unix

func (t *Timestamp) Unix() int64

Unix 返回秒级时间戳 noinspection all

func (*Timestamp) UnixMicro

func (t *Timestamp) UnixMicro() int64

UnixMicro 返回微秒级时间戳 noinspection all

func (*Timestamp) UnixMilli

func (t *Timestamp) UnixMilli() int64

UnixMilli 返回毫秒级时间戳 noinspection all

func (*Timestamp) UnixNano

func (t *Timestamp) UnixNano() int64

UnixNano 返回纳秒级时间戳 noinspection all

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(data []byte) error

UnmarshalJSON 实现 JSON 反序列化接口 noinspection all

func (Timestamp) Value

func (t Timestamp) Value() (driver.Value, error)

Value 实现 driver.Valuer 接口,将时间 转成微秒级时间戳 noinspection all

type Uint64

type Uint64 struct {
	// contains filtered or unexported fields
}

func NewUint64

func NewUint64(v uint64) Uint64

func (*Uint64) Equals

func (u *Uint64) Equals(other Uint64) bool

func (*Uint64) EqualsInt

func (u *Uint64) EqualsInt(other int) bool

func (*Uint64) EqualsUint64

func (u *Uint64) EqualsUint64(other uint64) bool

func (*Uint64) GetValue

func (u *Uint64) GetValue() uint64

func (Uint64) GormDBDataType

func (u Uint64) GormDBDataType(db *gorm.DB, field *schema.Field) string

noinspection all

func (*Uint64) Scan

func (u *Uint64) Scan(value any) error

noinspection all

func (*Uint64) SetValue

func (u *Uint64) SetValue(v uint64)

func (Uint64) Value

func (u Uint64) Value() (driver.Value, error)

noinspection all

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL