schema

package
v0.0.0-...-6e34f3e Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Bool   = schema.Bool
	Int    = schema.Int
	Int8   = schema.Int8
	Int16  = schema.Int16
	Int32  = schema.Int32
	Int64  = schema.Int64
	Uint   = schema.Uint
	Uint8  = schema.Uint8
	Uint16 = schema.Uint16
	Uint32 = schema.Uint32
	Uint64 = schema.Uint64
	Float  = schema.Float
	String = schema.String
	Text   = schema.Text
	JSON   = schema.JSON
	Time   = schema.Time
	Bytes  = schema.Bytes
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field struct {
	Default     interface{}     `json:"default,omitempty"`
	Unique      interface{}     `json:"unique,omitempty"`
	Index       interface{}     `json:"index,omitempty"`
	Comment     string          `json:"comment,omitempty"`
	Label       string          `json:"label"`
	Type        schema.DataType `json:"type"`
	Validations []Validations   `json:"validations,omitempty"`
	Options     FieldOption     `json:"options,omitempty"`
	Before      []string        `json:"-"`
	After       []string        `json:"-"`
	ValidRules  zvalid.Engine   `json:"-"`
	// 如果是数字类型则为长度,如果是字符串类型则为最大长度
	Size     uint64 `json:"size,omitempty"`
	Nullable bool   `json:"nullable,omitempty"`
}

func (*Field) GetValidations

func (f *Field) GetValidations() *zvalid.Engine

type FieldEnum

type FieldEnum struct {
	Value string `json:"value"`
	Label string `json:"label"`
}

type FieldOption

type FieldOption struct {
	FormatTime       string      `json:"format_time,omitempty"`
	Crypt            string      `json:"crypt,omitempty"`
	Enum             []FieldEnum `json:"enum,omitempty"`
	IsArray          bool        `json:"is_array,omitempty"`
	ReadOnly         bool        `json:"readonly,omitempty"`
	DisableMigration bool        `json:"disable_migration,omitempty"`
}

type Fields

type Fields map[string]Field

type Options

type Options struct {
	DisabledMigrator *bool `json:"disabled_migrator,omitempty"`
	SoftDeletes      *bool `json:"soft_deletes,omitempty"`
	Timestamps       *bool `json:"timestamps,omitempty"`
	CryptID          *bool `json:"crypt_id,omitempty"`
	Hook             func(event hook.Event, data ...any) error
	Salt             string   `json:"crypt_salt,omitempty"`
	LowFields        []string `json:"low_fields,omitempty"`
	FieldsSort       []string `json:"fields_sort,omitempty"`
	CryptLen         int      `json:"crypt_len,omitempty"`
}

func (*Options) SetCryptID

func (o *Options) SetCryptID(b bool) *Options

func (*Options) SetCryptLen

func (o *Options) SetCryptLen(i int) *Options

func (*Options) SetDisabledMigrator

func (o *Options) SetDisabledMigrator(b bool) *Options

func (*Options) SetHook

func (o *Options) SetHook(h func(event hook.Event, data ...any) error) *Options

func (*Options) SetSalt

func (o *Options) SetSalt(s string) *Options

func (*Options) SetSoftDeletes

func (o *Options) SetSoftDeletes(b bool) *Options

func (*Options) SetTimestamps

func (o *Options) SetTimestamps(b bool) *Options

type Relation

type Relation struct {
	Filter     ztype.Map          `json:"filter,omitempty"`
	Comment    string             `json:"comment,omitempty"`
	Label      string             `json:"label"`
	Type       RelationType       `json:"type"`
	Join       builder.JoinOption `json:"-"`
	Schema     string             `json:"schema"`
	ForeignKey []string           `json:"foreign_key"`
	SchemaKey  []string           `json:"schema_key"`
	Fields     []string           `json:"fields,omitempty"`
	Nullable   bool               `json:"nullable,omitempty"`
}

type RelationType

type RelationType string
const (
	// RelationSingle 单对单
	RelationSingle RelationType = "single"
	// RelationSingleMerge 单对单,结果合并
	RelationSingleMerge RelationType = "single_merge"
	// RelationMany 单对多
	RelationMany RelationType = "many"
)

type Relations

type Relations map[string]Relation

type Schema

type Schema struct {
	Options    Options    `json:"options,omitempty"`
	Fields     Fields     `json:"fields"`
	Extend     ztype.Map  `json:"extend,omitempty"`
	Relations  Relations  `json:"relations,omitempty"`
	Table      Table      `json:"table,omitempty"`
	Name       string     `json:"name"`
	SchemaPath string     `json:"-"`
	Values     ztype.Maps `json:"values,omitempty"`
}

func New

func New(name string, tableName ...string) Schema

func (*Schema) AddField

func (d *Schema) AddField(name string, field Field) error

func (*Schema) AddRelation

func (d *Schema) AddRelation(name string, relation Relation) error

func (*Schema) GetField

func (d *Schema) GetField(name string) (Field, bool)

func (*Schema) GetOptions

func (d *Schema) GetOptions() Options

func (*Schema) SetComment

func (d *Schema) SetComment(comment string)

func (*Schema) SetOptions

func (d *Schema) SetOptions(fn ...func(opt *Options)) *Options

type Schemas

type Schemas []Schema

func (*Schemas) Append

func (d *Schemas) Append(define ...Schema)

type Table

type Table struct {
	Name    string `json:"name,omitempty"`
	Comment string `json:"comment,omitempty"`
}

type Validations

type Validations struct {
	Args    interface{} `json:"args"`
	Method  string      `json:"method"`
	Message string      `json:"message,omitempty"`
}

Jump to

Keyboard shortcuts

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