types

package
v0.3.7 Latest Latest
Warning

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

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

Documentation

Overview

* @Author: kamalyes 501893067@qq.com * @Date: 2025-11-11 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2026-05-08 15:00:00 * @FilePath: \go-sqlbuilder\types\helpers.go * @Description: 内部辅助函数 * * Copyright (c) 2025 by kamalyes, All Rights Reserved.

* @Author: kamalyes 501893067@qq.com * @Date: 2025-11-11 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2026-05-08 15:05:00 * @FilePath: \go-sqlbuilder\types\json.go * @Description: JSON - 泛型 JSON 类型,支持任意可序列化类型的数据库存储 * * Copyright (c) 2025 by kamalyes, All Rights Reserved.

* @Author: kamalyes 501893067@qq.com * @Date: 2025-11-11 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2026-05-08 15:15:19 * @FilePath: \go-sqlbuilder\types\map_any.go * @Description: MapAny - 任意类型 Map,支持数据库 JSON 序列化 * * Copyright (c) 2025 by kamalyes, All Rights Reserved.

* @Author: kamalyes 501893067@qq.com * @Date: 2026-05-09 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2026-05-11 12:57:50 * @FilePath: \go-sqlbuilder\types\proto_json.go * @Description: ProtoJSON - 泛型 protobuf JSON 类型,支持 protobuf 消息的数据库存储 * * Copyright (c) 2026 by kamalyes, All Rights Reserved.

* @Author: kamalyes 501893067@qq.com * @Date: 2025-11-11 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2026-05-08 15:00:00 * @FilePath: \go-sqlbuilder\types\slice.go * @Description: Slice - 泛型切片类型,支持数据库 JSON 序列化 * * Copyright (c) 2025 by kamalyes, All Rights Reserved.

* @Author: kamalyes 501893067@qq.com * @Date: 2025-11-11 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2026-05-08 15:00:00 * @FilePath: \go-sqlbuilder\types\string_slice.go * @Description: StringSlice - 字符串切片,支持数据库 JSON 序列化和分隔符解析 * * Copyright (c) 2025 by kamalyes, All Rights Reserved.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JSON

type JSON[T any] struct {
	Data T
}

JSON 泛型 JSON 类型,支持任意可序列化类型

func (*JSON[T]) Get

func (j *JSON[T]) Get() T

Get 获取数据

func (*JSON[T]) Scan

func (j *JSON[T]) Scan(value interface{}) error

func (*JSON[T]) Set

func (j *JSON[T]) Set(data T)

Set 设置数据

func (JSON[T]) Value

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

type MapAny

type MapAny map[string]any

MapAny 任意类型的 Map,支持数据库 JSON 序列化

func (MapAny) Clone

func (m MapAny) Clone() MapAny

Clone 克隆一个新的 Map

func (MapAny) Delete

func (m MapAny) Delete(key string) MapAny

Delete 删除指定 key

func (MapAny) Get

func (m MapAny) Get(key string, defaultValue ...any) any

Get 获取指定 key 的值,支持默认值

func (MapAny) GetBool

func (m MapAny) GetBool(key string, defaultValue ...bool) bool

GetBool 获取布尔值

func (MapAny) GetInt

func (m MapAny) GetInt(key string, defaultValue ...int) int

GetInt 获取整数值

func (MapAny) GetString

func (m MapAny) GetString(key string, defaultValue ...string) string

GetString 获取字符串值

func (MapAny) Has

func (m MapAny) Has(key string) bool

Has 检查 key 是否存在

func (MapAny) Keys

func (m MapAny) Keys() []string

Keys 获取所有 key

func (MapAny) Merge

func (m MapAny) Merge(other MapAny) MapAny

Merge 合并另一个 Map

func (*MapAny) Scan

func (m *MapAny) Scan(value interface{}) error

func (MapAny) Set

func (m MapAny) Set(key string, value any) MapAny

Set 设置值

func (MapAny) Value

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

func (MapAny) Values

func (m MapAny) Values() []any

Values 获取所有 value

type ProtoJSON

type ProtoJSON[T any] struct {
	Data T
}

ProtoJSON 泛型 protobuf JSON 类型,支持 protobuf 消息的数据库存储

func (*ProtoJSON[T]) Get

func (p *ProtoJSON[T]) Get() T

Get - 获取结构体字段值

func (*ProtoJSON[T]) Scan

func (p *ProtoJSON[T]) Scan(value interface{}) error

Scan - 从数据库值扫描 protobuf JSON 类型

func (*ProtoJSON[T]) Set

func (p *ProtoJSON[T]) Set(data T)

Set - 设置 protobuf JSON 类型值

func (*ProtoJSON[T]) Value

func (p *ProtoJSON[T]) Value() (driver.Value, error)

Value - 将 protobuf JSON 类型转换为数据库值

type ProtoJSONMap

type ProtoJSONMap[T proto.Message] struct {
	Fields map[string]ProtoJSON[T]
}

ProtoJSONMap - 泛型 protobuf JSON 类型,支持 protobuf 消息的数据库存储

func NewProtoJSONMap

func NewProtoJSONMap[T proto.Message]() *ProtoJSONMap[T]

NewProtoJSONMap - 创建一个新的 protobuf JSON 类型映射

func (*ProtoJSONMap[T]) Get

func (p *ProtoJSONMap[T]) Get(key string) T

Get - 获取指定键的 protobuf JSON 类型值

func (*ProtoJSONMap[T]) Keys

func (p *ProtoJSONMap[T]) Keys() []string

Keys - 获取所有键

func (*ProtoJSONMap[T]) Scan

func (p *ProtoJSONMap[T]) Scan(value interface{}) error

func (*ProtoJSONMap[T]) Set

func (p *ProtoJSONMap[T]) Set(key string, data T)

Set - 设置指定键的 protobuf JSON 类型值

func (ProtoJSONMap[T]) Value

func (p ProtoJSONMap[T]) Value() (driver.Value, error)

Value - 将 protobuf JSON 类型转换为数据库值

type Slice

type Slice[T any] []T

Slice 泛型切片类型

func Map

func Map[T any, R any](s Slice[T], fn func(T) R) Slice[R]

Map 映射转换

func (*Slice[T]) Append

func (s *Slice[T]) Append(items ...T) Slice[T]

Append 追加元素

func (Slice[T]) Clone

func (s Slice[T]) Clone() Slice[T]

Clone 克隆切片

func (Slice[T]) Filter

func (s Slice[T]) Filter(fn func(T) bool) Slice[T]

Filter 过滤元素

func (Slice[T]) Len

func (s Slice[T]) Len() int

Len 获取长度

func (*Slice[T]) Scan

func (s *Slice[T]) Scan(value interface{}) error

func (Slice[T]) Value

func (s Slice[T]) Value() (driver.Value, error)

type StringSlice

type StringSlice []string

StringSlice 字符串切片,支持数据库 JSON 序列化

func ParseStringSlice

func ParseStringSlice(input []string) StringSlice

ParseStringSlice 从混合格式解析字符串切片 支持数组或分隔字符串 (分号;换行符\n)

func (*StringSlice) Append

func (s *StringSlice) Append(items ...string) StringSlice

Append 追加元素

func (StringSlice) Clone

func (s StringSlice) Clone() StringSlice

Clone 克隆一个新的切片

func (StringSlice) Contains

func (s StringSlice) Contains(item string) bool

Contains 检查是否包含指定元素

func (StringSlice) Filter

func (s StringSlice) Filter(fn func(string) bool) StringSlice

Filter 过滤元素

func (*StringSlice) FromDelimitedString

func (s *StringSlice) FromDelimitedString(input string, delimiters ...string) StringSlice

FromDelimitedString 从分隔符字符串创建 StringSlice 支持多种分隔符: 分号(;)、换行符(\n)、逗号(,) 自动去除空白字符和空字符串

func (StringSlice) IndexOf

func (s StringSlice) IndexOf(item string) int

IndexOf 查找元素索引,未找到返回 -1

func (StringSlice) Join

func (s StringSlice) Join(sep string) string

Join 连接为字符串

func (StringSlice) Map

func (s StringSlice) Map(fn func(string) string) StringSlice

Map 映射转换

func (*StringSlice) Remove

func (s *StringSlice) Remove(item string) StringSlice

Remove 移除指定元素(第一个匹配的)

func (*StringSlice) RemoveAt

func (s *StringSlice) RemoveAt(index int) StringSlice

RemoveAt 移除指定索引的元素

func (*StringSlice) Scan

func (s *StringSlice) Scan(value interface{}) error

func (StringSlice) Unique

func (s StringSlice) Unique() StringSlice

Unique 去重

func (StringSlice) Value

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

Jump to

Keyboard shortcuts

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