sqlX

package
v2.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JsonColumn

type JsonColumn[T any] struct {
	Val   T    // 存储实际数据
	Valid bool // 表示该字段在数据库中是否为非 NULL
}

JsonColumn 是一个支持 NULL 的泛型 JSON 列包装器 类似 sql.NullString,但用于任意可 JSON 序列化的类型

func (JsonColumn[T]) MarshalJSON

func (j JsonColumn[T]) MarshalJSON() ([]byte, error)

MarshalJSON 实现 json.Marshaler 接口 当 Valid 为 true 时,直接序列化 Val 的值;否则序列化为 null

func (*JsonColumn[T]) Scan

func (j *JsonColumn[T]) Scan(src any) error

Scan 实现 sql.Scanner 接口 从数据库读取值([]byte, string, nil)并反序列化到 j.Val

func (*JsonColumn[T]) UnmarshalJSON

func (j *JsonColumn[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON 实现 json.Unmarshaler 接口 当输入为 null 时,设置 Valid 为 false;否则反序列化到 Val

func (JsonColumn[T]) Value

func (j JsonColumn[T]) Value() (driver.Value, error)

Value 实现 driver.Valuer 接口 将 Go 值转换为数据库存储值([]byte 或 nil)

Jump to

Keyboard shortcuts

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