schema

package
v0.0.0-...-f549517 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrValueNil         = errors.New("wxorm: value is nil")
	ErrValueNotStruct   = errors.New("wxorm: value is not Struct or *Struct")
	ErrModelNotStruct   = errors.New("wxorm: model is not Struct or *Struct")
	ErrModelNilPointer  = errors.New("wxorm: model pointer is nil")
	ErrModelEmptyFields = errors.New("wxorm: model struct has no available field")
	ErrValuesEmpty      = errors.New("wxorm: values is empty")
)

Functions

func GetModelStruct

func GetModelStruct(model any) (reflect.Value, error)

GetModelStruct 获取数据模型的数据结构

func GetReflectFieldValue

func GetReflectFieldValue(field reflect.Value) (value any, zero bool)

GetReflectFieldValue 获取反射字段的值

func IsZeroValue

func IsZeroValue(value reflect.Value) bool

IsZeroValue 判断是否为零值

func PutToCache

func PutToCache(key string, sch *Schema)

PutToCache 缓存 Schema

Types

type Schema

type Schema struct {
	TableName              string                 // 数据表名
	ModelName              string                 // 数据模型名称
	ModelType              reflect.Type           // 数据模型类型
	Model                  any                    // 数据模型
	Fields                 []*reflect.StructField // 数据模型字段
	Methods                []*reflect.Method      // 数据模型方法
	Columns                []column.Column        // 数据表字段列表
	ColumnNames            []string               // 数据表字段名列表
	ColumnIndexesInModel   []int                  // 数据表字段索引列表(数据表字段在对应的数据模型中的索引)
	InsertableColumnNames  []string               // 数据表可插入字段名列表
	InsertableFieldIndexes []int                  // 数据模型可插入字段索引列表
}

Schema 定义数据表的数据结构

func GetFromCache

func GetFromCache(key string) (*Schema, bool)

GetFromCache 从缓存中获取 Schema

func Parse

func Parse(dial dialect.Dialect, model any) (*Schema, error)

Parse 解析 Go 结构体数据模型与数据表的对应关系

  • dial: 对应数据库的 dialect.Dialect
  • model: 数据表对应的数据模型,推荐使用 *Struct 格式

func (*Schema) ExtractPrimaryKeyValues

func (own *Schema) ExtractPrimaryKeyValues(value reflect.Value) (pkNames []string, pkValues []any, isZero bool)

ExtractPrimaryKeyValues 提取数据主键数据

func (*Schema) ExtractValue

func (own *Schema) ExtractValue(value any) ([]any, error)

ExtractValue 从结构体中提取单个数据

  • value:数据格式 Struct 或 *Struct

func (*Schema) GetColumnByName

func (own *Schema) GetColumnByName(name string) (column.Column, error)

GetColumnByName 根据字段名获取数据字段

type TableNameGetter

type TableNameGetter interface {
	GetTableName() string
}

Jump to

Keyboard shortcuts

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