schema

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2025 License: Apache-2.0 Imports: 16 Imported by: 8

Documentation

Index

Constants

View Source
const (
	IndexTag      = "index"
	IndexName     = "NAME"
	IndexSort     = "SORT"
	IndexUnique   = "UNIQUE"
	IndexSparse   = "SPARSE"
	IndexPartial  = "PARTIAL" //部分索引 index:"PARTIAL:{\"invite\":{\"$gt\":0}}"`
	IndexPriority = "PRIORITY"
)

https://www.mongodb.com/zh-cn/docs/manual/core/index-partial/#std-label-index-type-partial 部分索引 使用一条查询语句

Variables

View Source
var ErrUnsupportedDataType = errors.New("unsupported data type")

ErrUnsupportedDataType unsupported data type

Functions

func Kind

func Kind(dest interface{}) reflect.Type

func ParseTagSetting

func ParseTagSetting(str string, sep string) map[string]string

func ToArray

func ToArray(v interface{}) (r []interface{})

func ToInt added in v1.1.0

func ToInt(i any) (r int64)

func ToInt32 added in v1.1.0

func ToInt32(i any) int32

func ToString

func ToString(value interface{}) string

func ValueOf

func ValueOf(i interface{}) reflect.Value

Types

type Field

type Field struct {
	Name              string
	Index             []int
	JSName            string
	DBName            string
	Schema            *Schema //所在的父对象
	Embedded          *Schema //嵌入子对象
	FieldType         reflect.Type
	StructField       reflect.StructField
	IndirectFieldType reflect.Type
}

func (*Field) Get added in v1.1.0

func (field *Field) Get(value reflect.Value) reflect.Value

func (*Field) GetEmbeddedFields added in v1.1.0

func (field *Field) GetEmbeddedFields() (r []*Field)

func (*Field) GetName added in v1.2.0

func (field *Field) GetName(ks ...string) string

GetName json,form,.... 按照ks 指定的顺寻找以名字,所有TAG 都无法匹配时返回字段名

func (*Field) GetTagName added in v1.2.0

func (field *Field) GetTagName(k string) string

func (*Field) ReflectValueOf

func (field *Field) ReflectValueOf(value reflect.Value) reflect.Value

func (*Field) Set

func (field *Field) Set(value reflect.Value, v interface{}) error

Set valuer, setter when parse struct

func (*Field) SetBool added in v1.1.0

func (field *Field) SetBool(value reflect.Value, v interface{}) error

func (*Field) SetFloat added in v1.1.0

func (field *Field) SetFloat(value reflect.Value, v interface{}) error

func (*Field) SetInt added in v1.1.0

func (field *Field) SetInt(value reflect.Value, v interface{}) error

func (*Field) SetString added in v1.1.0

func (field *Field) SetString(value reflect.Value, v interface{}) error

func (*Field) SetUint added in v1.1.0

func (field *Field) SetUint(value reflect.Value, v interface{}) error

type Index

type Index struct {
	Name    string
	Unique  bool //唯一
	Sparse  bool //稀疏索引
	Partial []string
	Fields  []*IndexField
	// contains filtered or unexported fields
}

func (*Index) Build

func (this *Index) Build(whereParser ...IndexPartialParse) (index *mongo.IndexModel, err error)

type IndexField

type IndexField struct {
	Sort     string   // DESC, ASC
	Name     string   // index name
	DBName   []string // a.b.c
	Unique   bool     //唯一
	Sparse   bool     //稀疏索引
	Partial  string   //{ rating: { $gt: 5 } }
	Priority int      //排序字段之间的排序ASC
}

func (*IndexField) GetDBName

func (this *IndexField) GetDBName() string

type IndexPartialParse added in v1.2.0

type IndexPartialParse func(*Schema, []string) (any, error)

type Namer

type Namer interface {
	TableName(table string) string
	ColumnName(table, column string) string
}

Namer Namer interface

type NamingStrategy

type NamingStrategy struct {
	TablePrefix   string
	SingularTable bool
	NameReplacer  Replacer
	NoLowerCase   bool
}

NamingStrategy tables, columns naming strategy

func (NamingStrategy) ColumnName

func (ns NamingStrategy) ColumnName(table, column string) string

ColumnName convert string to column name

func (NamingStrategy) TableName

func (ns NamingStrategy) TableName(str string) string

TableName convert string to table name

type Options

type Options struct {
	Namer
	Store *sync.Map
}

func New

func New(namer ...Namer) (i *Options)

New 新封装schema Store Namer

func (*Options) Parse

func (opts *Options) Parse(dest interface{}) (*Schema, error)

func (*Options) ParseWithSpecialTableName

func (opts *Options) ParseWithSpecialTableName(dest interface{}, name string) (*Schema, error)

type Replacer

type Replacer interface {
	Replace(name string) string
}

Replacer replacer interface like strings.Replacer

type Schema

type Schema struct {
	Name      string
	Table     string
	Embedded  []*Field //嵌入字段
	ModelType reflect.Type
	Fields    map[string]*Field
	// contains filtered or unexported fields
}

func GetOrParse added in v1.1.0

func GetOrParse(dest interface{}, opts *Options) (*Schema, error)

func Parse

func Parse(dest interface{}) (*Schema, error)

Parse get data type from dialector

func ParseWithSpecialTableName

func ParseWithSpecialTableName(dest interface{}, specialTableName string, opts *Options) (*Schema, error)

ParseWithSpecialTableName get data type from dialector with extra schema table

func (*Schema) GetValue

func (schema *Schema) GetValue(obj any, key string, keys ...any) (r any)

func (*Schema) JSName added in v1.2.0

func (schema *Schema) JSName(k string) (r string)

func (*Schema) LookIndex

func (schema *Schema) LookIndex(name string) *Index

func (*Schema) LookUpField

func (schema *Schema) LookUpField(name string) *Field

func (*Schema) Make added in v1.1.0

func (schema *Schema) Make() reflect.Value

Make Make a Slice

func (*Schema) New

func (schema *Schema) New() reflect.Value

func (*Schema) ParseField

func (schema *Schema) ParseField(fieldStruct reflect.StructField) *Field

func (*Schema) ParseIndexes

func (schema *Schema) ParseIndexes() map[string]*Index

ParseIndexes parse schema indexes

func (*Schema) Range added in v1.1.0

func (schema *Schema) Range(cb func(*Field) bool)

Range 遍历字段

func (*Schema) SetValue

func (schema *Schema) SetValue(obj any, val any, key string, keys ...any) (err error)

func (*Schema) String

func (schema *Schema) String() string

type Tabler

type Tabler interface {
	TableName() string
}

Jump to

Keyboard shortcuts

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