sqlx

package
v0.0.0-...-eeaec48 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewNullBool

func NewNullBool(val bool) sql.NullBool

func NewNullBytes

func NewNullBytes(val []byte) sql.NullString

func NewNullFloat64

func NewNullFloat64(val float64) sql.NullFloat64

func NewNullInt64

func NewNullInt64(val int64) sql.NullInt64

func NewNullString

func NewNullString(val string) sql.NullString

func NewNullTime

func NewNullTime(val time.Time) sql.NullTime

Types

type JsonColumn

type JsonColumn[T any] struct {
	Val   T
	Valid bool
}

JsonColumn 代表存储字段的 json 类型 主要用于没有提供默认 json 类型的数据库 T 可以是结构体,也可以是切片或者 map 理论上来说一切可以被 json 库所处理的类型都能被用作 T 不建议使用指针作为 T 的类型 如果 T 是指针,那么在 Val 为 nil 的情况下,一定要把 Valid 设置为 false

func (*JsonColumn[T]) Scan

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

Scan 将 src 转化为对象 src 的类型必须是 []byte, string 或者 nil 如果是 nil,我们不会做任何处理

func (JsonColumn[T]) Value

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

Value 返回一个 json 串。类型是 []byte

type Rows

type Rows interface {
	Next() bool
	NextResultSet() bool
	Err() error
	Columns() ([]string, error)
	// ColumnTypes 还是返回了原本的 sql.ColumnType
	// 因为 ColumnType 同样不是一个接口,所以为了兼容 sql.Rows,
	// 就只有保持这个设计
	ColumnTypes() ([]*sql.ColumnType, error)
	Scan(dest ...any) error
	Close() error
}

Jump to

Keyboard shortcuts

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