schema

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 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

View Source
var TimeReflectType = reflect.TypeOf(time.Time{})

Functions

func ParseTagSetting

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

Types

type BeforeCreate added in v1.0.0

type BeforeCreate interface {
	BeforeCreate() []clause.Interface
}

type DataType added in v1.0.0

type DataType string
const (
	Bool   DataType = "bool"
	Int    DataType = "int"
	Uint   DataType = "uint"
	Float  DataType = "float"
	String DataType = "string"
	Time   DataType = "time"
	Bytes  DataType = "bytes"
)

type Field

type Field struct {
	Name                   string
	DBName                 string
	BindNames              []string
	DataType               DataType
	GORMDataType           DataType
	PrimaryKey             bool
	AutoIncrement          bool
	AutoIncrementIncrement int64
	Creatable              bool
	Updatable              bool
	Readable               bool
	HasDefaultValue        bool
	AutoCreateTime         TimeType
	AutoUpdateTime         TimeType
	DefaultValue           string
	DefaultValueInterface  interface{}
	NotNull                bool
	Unique                 bool
	Comment                string
	Size                   int
	Precision              int
	Scale                  int
	FieldType              reflect.Type
	IndirectFieldType      reflect.Type
	StructField            reflect.StructField
	Tag                    reflect.StructTag
	TagSettings            map[string]string
	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
	IgnoreMigration        bool
}

type GormDataTypeInterface

type GormDataTypeInterface interface {
	GormDataType() string
}

type Index

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

type IndexOption added in v1.0.0

type IndexOption struct {
	*Field
	Sort string // DESC, ASC
	// contains filtered or unexported fields
}

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 Namer
	Store *sync.Map
}

func New

func New() (i *Options)

New 新封装schema Store Namer

func (*Options) Parse

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

Parse get data type from dialector

func (*Options) ParseWithSpecialTableName

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

ParseWithSpecialTableName get data type from dialector with extra schema table

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 (Schema) FieldDBName

func (schema Schema) FieldDBName(name string) string

FieldDBName 查询对象字段对应的DBName

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
}

type TimeType added in v1.0.0

type TimeType int64
const (
	UnixTime        TimeType = 1
	UnixSecond      TimeType = 2
	UnixMillisecond TimeType = 3
	UnixNanosecond  TimeType = 4
)

Jump to

Keyboard shortcuts

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