schema

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2021 License: MIT Imports: 14 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

func ToString

func ToString(value interface{}) string

Types

type DataType

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
	Precision         int
	FieldType         reflect.Type
	IndirectFieldType reflect.Type
	StructField       reflect.StructField
	TagSettings       map[string]string
	ReflectValueOf    func(reflect.Value) reflect.Value
	ValueOf           func(reflect.Value) (value interface{}, zero bool)
	Set               func(reflect.Value, interface{}) error
}

type Namer

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

type NamingStrategy

type NamingStrategy struct {
	TablePrefix  string
	NameReplacer Replacer
}

func (NamingStrategy) ColumnName

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

func (NamingStrategy) IndexName

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

func (NamingStrategy) SchemaName

func (ns NamingStrategy) SchemaName(table string) string

func (NamingStrategy) TableName

func (ns NamingStrategy) TableName(str string) string

type Replacer

type Replacer interface {
	Replace(name string) string
}

type Schema

type Schema struct {
	Name           string
	Table          string
	ModelType      reflect.Type
	FieldsByName   map[string]*Field
	FieldsByDBName map[string]*Field
	Fields         []*Field
	DBNames        []string
	// contains filtered or unexported fields
}

func Parse

func Parse(dest interface{}, cacheStore *sync.Map, namer Namer) (*Schema, error)

func (Schema) LookUpField

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

func (*Schema) ParseField

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

Jump to

Keyboard shortcuts

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