schema

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2022 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

ErrUnsupportedDataType unsupported data type

Functions

func ParseTagSetting

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

Types

type Field

type Field struct {
	Name              string
	DBName            string
	FieldType         reflect.Type
	IndirectFieldType reflect.Type
	StructField       reflect.StructField
	Schema            *Schema
	EmbeddedSchema    *Schema //嵌入子对象
	//OwnerSchema    *Schema
	ReflectValueOf func(reflect.Value) reflect.Value
	//ValueOf        func(reflect.Value) (value interface{}, zero bool)
	Set func(reflect.Value, interface{}) error
}

type GormDataTypeInterface

type GormDataTypeInterface interface {
	GormDataType() string
}

type Index

type Index struct {
	Name   string
	Unique bool //唯一
	Sparse bool //稀疏索引
	Fields []*IndexField
}

func (*Index) Build

func (this *Index) Build() (index mongo.IndexModel)

type IndexField

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

func (*IndexField) GetDBName

func (this *IndexField) GetDBName() string

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
	Fields         []*Field
	ModelType      reflect.Type
	FieldsByName   map[string]*Field
	FieldsByDBName map[string]*Field
	// contains filtered or unexported fields
}

func Parse

func Parse(dest interface{}, opts *Options) (*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) FieldDBName

func (schema Schema) FieldDBName(name string) string

FieldDBName 查询对象字段对应的DBName

func (Schema) GetValue

func (schema Schema) GetValue(i interface{}, key string) interface{}

func (*Schema) LookIndex

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

func (Schema) LookUpField

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

func (Schema) MakeSlice

func (schema Schema) MakeSlice() reflect.Value

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) 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