types

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DatetimeZero     = Datetime{Timestamp: TimestampZero}
	DatetimeUnixZero = Datetime{Timestamp: TimestampUnixZero}
)
View Source
var (
	UTC = time.UTC
	// CST Chinese Standard Timezone
	CST = must.NoErrorV(time.LoadLocation("Asia/Shanghai"))
	// JST Japan Standard Timezone
	JST = must.NoErrorV(time.LoadLocation("Asia/Tokyo"))
	// KST Korea Standard Timezone
	KST = must.NoErrorV(time.LoadLocation("Asia/Seoul"))
	// IST Indochina Standard Timezone (Thailand)
	IST = must.NoErrorV(time.LoadLocation("Asia/Bangkok"))

	TimestampZero     = Timestamp{time.Time{}}
	TimestampUnixZero = Timestamp{time.Unix(0, 0)}
	DefaultTimeLayout = "2006-01-02 15:04:05.000"
)

Functions

func AddTimeInputLayouts

func AddTimeInputLayouts(layouts ...string)

func DriverJSONValue

func DriverJSONValue(v any) (driver.Value, error)

DriverJSONValue unmarshal input to driver.Value

func GetTimeInputLayouts

func GetTimeInputLayouts() []string

func GetTimeOutputLayout

func GetTimeOutputLayout() string

func GetTimezone

func GetTimezone() *time.Location

func HasSoftDeletion

func HasSoftDeletion[M internal.Model]() bool

func ScanJSONValue

func ScanJSONValue(src, dst any) error

ScanJSONValue scan database input to value

func SetTimeOutputLayout

func SetTimeOutputLayout(layout string)

func SetTimezone

func SetTimezone(timezone *time.Location)

Types

type AutoIncID

type AutoIncID struct {
	ID uint64 `db:"f_id,autoinc" json:"-"`
}

type Blob

type Blob []byte

func (Blob) DBType

func (Blob) DBType(driver string) string

func (*Blob) Scan

func (v *Blob) Scan(src any) error

func (*Blob) Set

func (v *Blob) Set(x []byte)

func (Blob) Value

func (v Blob) Value() (driver.Value, error)

type Bool

type Bool int
const (
	TRUE  Bool // true
	FALSE      // false
)

func Boolean

func Boolean(b bool) Bool

func (Bool) Bool

func (v Bool) Bool() bool

func (Bool) MarshalJSON

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

func (Bool) MarshalText

func (v Bool) MarshalText() ([]byte, error)

func (*Bool) UnmarshalJSON

func (v *Bool) UnmarshalJSON(data []byte) (err error)

func (*Bool) UnmarshalText

func (v *Bool) UnmarshalText(data []byte) error

type CreationDatetime

type CreationDatetime struct {
	// CreatedAt 创建日期时间(毫秒)
	CreatedAt Datetime `db:"f_created_at,precision=3,default=CURRENT_TIMESTAMP(3)" json:"createdAt"`
}

func (*CreationDatetime) MarkCreatedAt

func (c *CreationDatetime) MarkCreatedAt()

type CreationMarker

type CreationMarker interface {
	MarkCreatedAt()
}

type CreationModificationDatetime

type CreationModificationDatetime struct {
	CreationDatetime
	// UpdatedAt 更新日期时间(毫秒)
	UpdatedAt Datetime `db:"f_updated_at,precision=3,default=CURRENT_TIMESTAMP(3),onupdate=CURRENT_TIMESTAMP(3)" json:"updatedAt"`
}

func (*CreationModificationDatetime) MarkCreatedAt

func (cu *CreationModificationDatetime) MarkCreatedAt()

func (*CreationModificationDatetime) MarkModifiedAt

func (cu *CreationModificationDatetime) MarkModifiedAt()

type CreationModificationDeletionDatetime

type CreationModificationDeletionDatetime struct {
	CreationModificationDatetime
	// DeletedAt 删除日期时间(毫秒)
	DeletedAt Datetime `db:"f_deleted_at,precision=3,default='0001-01-01 00:00:00.000'" json:"deletedAt"`
}

func (*CreationModificationDeletionDatetime) MarkDeletedAt

func (cud *CreationModificationDeletionDatetime) MarkDeletedAt()

func (CreationModificationDeletionDatetime) SoftDeletion

type CreationModificationDeletionTime

type CreationModificationDeletionTime struct {
	CreationModificationTime
	// DeletedAt 删除时间 毫秒时间戳
	DeletedAt Timestamp `db:"f_deleted_at,default='0'" json:"deletedAt,omitempty"`
}

func (*CreationModificationDeletionTime) MarkDeletedAt

func (cmd *CreationModificationDeletionTime) MarkDeletedAt()

func (CreationModificationDeletionTime) SoftDeletion

func (cmd CreationModificationDeletionTime) SoftDeletion() (string, []string, driver.Value)

type CreationModificationTime

type CreationModificationTime struct {
	CreationTime
	// UpdatedAt 更新时间 毫秒时间戳
	UpdatedAt Timestamp `db:"f_updated_at,default='0'" json:"updatedAt"`
}

func (*CreationModificationTime) MarkCreatedAt

func (cu *CreationModificationTime) MarkCreatedAt()

func (*CreationModificationTime) MarkModifiedAt

func (cu *CreationModificationTime) MarkModifiedAt()

type CreationTime

type CreationTime struct {
	// CreatedAt 创建时间 毫秒时间戳
	CreatedAt Timestamp `db:"f_created_at,default='0'" json:"createdAt"`
}

func (*CreationTime) MarkCreatedAt

func (c *CreationTime) MarkCreatedAt()

type DBTypeAdapter

type DBTypeAdapter interface {
	WithDBType(driver string)
}

type DBValue

type DBValue interface {
	driver.Valuer
	sql.Scanner
	DBType(driver string) string
}

DBValue can convert between rdb value and go value with description of rdb datatype

type Datetime

type Datetime struct {
	Timestamp
}

func AsDatetime

func AsDatetime(t time.Time) Datetime

func (Datetime) DBType

func (Datetime) DBType(driver string) string

func (*Datetime) Scan

func (t *Datetime) Scan(src any) error

func (Datetime) Value

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

type Decimal

type Decimal struct {
	decimal.Decimal
}

func AsDecimal

func AsDecimal(v decimal.Decimal) Decimal

func (*Decimal) DBType

func (d *Decimal) DBType(driver string) string

type DeletionMarker

type DeletionMarker interface {
	MarkDeletedAt()
}

type ID

type ID uint64

type JSONArray

type JSONArray[T any] struct {
	JSONDBType
	// contains filtered or unexported fields
}

func JSONArrayOf

func JSONArrayOf[T any](s []T) *JSONArray[T]

func (*JSONArray[T]) Get

func (v *JSONArray[T]) Get() []T

func (JSONArray[T]) IsZero

func (v JSONArray[T]) IsZero() bool

func (JSONArray[T]) MarshalJSON

func (v JSONArray[T]) MarshalJSON() ([]byte, error)

func (*JSONArray[T]) Scan

func (v *JSONArray[T]) Scan(src any) error

func (*JSONArray[T]) Set

func (v *JSONArray[T]) Set(x []T)

func (*JSONArray[T]) UnmarshalJSON

func (v *JSONArray[T]) UnmarshalJSON(data []byte) error

func (JSONArray[T]) Value

func (v JSONArray[T]) Value() (driver.Value, error)

type JSONDBType

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

func (JSONDBType) DBType

func (t JSONDBType) DBType() string

func (*JSONDBType) WithDBType

func (t *JSONDBType) WithDBType(typ string)

type JSONObject

type JSONObject[T any] struct {
	JSONDBType
	// contains filtered or unexported fields
}

func JSONObjectOf

func JSONObjectOf[T any](v *T) JSONObject[T]

func (*JSONObject[T]) Get

func (v *JSONObject[T]) Get() *T

func (JSONObject[T]) IsZero

func (v JSONObject[T]) IsZero() bool

func (JSONObject[T]) MarshalJSON

func (v JSONObject[T]) MarshalJSON() ([]byte, error)

func (*JSONObject[T]) Scan

func (v *JSONObject[T]) Scan(src any) error

func (*JSONObject[T]) Set

func (v *JSONObject[T]) Set(x *T)

func (*JSONObject[T]) UnmarshalJSON

func (v *JSONObject[T]) UnmarshalJSON(data []byte) error

func (JSONObject[T]) Value

func (v JSONObject[T]) Value() (driver.Value, error)

type ModificationMarker

type ModificationMarker interface {
	MarkModifiedAt()
}

type SoftDeletion

type SoftDeletion interface {
	// SoftDeletion returns soft deletion field name, modifications fields if exists
	// and default value of deletion field
	SoftDeletion() (deletion string, modifications []string, v driver.Value)
}

type Text

type Text string

func (Text) DBType

func (Text) DBType(driver string) string

func (*Text) Scan

func (v *Text) Scan(src any) error

func (*Text) Set

func (v *Text) Set(str string)

func (Text) Value

func (v Text) Value() (driver.Value, error)

type Timestamp

type Timestamp struct {
	time.Time `json:",inline"`
}

func AsTimestamp

func AsTimestamp(t time.Time) Timestamp

func ParseTimestamp

func ParseTimestamp(input string) (d Timestamp, err error)

func ParseTimestampWithLayout

func ParseTimestampWithLayout(input, layout string) (Timestamp, error)

func (Timestamp) DBType

func (Timestamp) DBType(driver string) string

func (Timestamp) Format

func (t Timestamp) Format(layout string) string

func (Timestamp) Int

func (t Timestamp) Int() int64

func (Timestamp) IsZero

func (t Timestamp) IsZero() bool

func (Timestamp) MarshalJSON

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

func (Timestamp) MarshalText

func (t Timestamp) MarshalText() ([]byte, error)

func (*Timestamp) Scan

func (t *Timestamp) Scan(src any) error

func (Timestamp) String

func (t Timestamp) String() string

func (*Timestamp) UnmarshalJSON

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

func (*Timestamp) UnmarshalText

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

func (Timestamp) Unwrap

func (t Timestamp) Unwrap() time.Time

func (Timestamp) Value

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

Jump to

Keyboard shortcuts

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