model

package
v2.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package model 管理数据模型

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Column

type Column struct {
	Name     string       // 数据库的字段名
	Len1     int          // 长度1,仅对部分类型启作用
	Len2     int          // 长度2,仅对部分类型启作用
	Nullable bool         // 是否可以为 NULL
	GoType   reflect.Type // Go 语言中的数据类型

	GoName string // 结构字段名

	HasDefault bool
	Default    string // 默认值
	// contains filtered or unexported fields
}

Column 列结构

func (*Column) IsAI

func (c *Column) IsAI() bool

IsAI 当前列是否为自增列

func (*Column) IsZero

func (c *Column) IsZero(v reflect.Value) bool

IsZero 是否为零值

type ConType added in v2.1.1

type ConType int8

ConType 约束类型

const (
	Index ConType = iota
	Unique
	Fk
	Check
)

预定的约束类型,方便 Model 中使用。

func (ConType) String added in v2.1.1

func (t ConType) String() string

type ForeignKey

type ForeignKey struct {
	Col                      *Column
	RefTableName, RefColName string
	UpdateRule, DeleteRule   string
}

ForeignKey 外键

type Metaer

type Metaer interface {
	Meta() string
}

Metaer 用于指定一个表级别的元数据。如表名,存储引擎等:

"name(tbl_name);engine(myISAM);charset(utf8)"

type Model

type Model struct {
	Name          string                 // 表的名称
	Cols          []*Column              // 所有的列
	KeyIndexes    map[string][]*Column   // 索引列
	UniqueIndexes map[string][]*Column   // 唯一索引列
	FK            map[string]*ForeignKey // 外键
	PK            []*Column              // 主键
	AI            *Column                // 自增列
	OCC           *Column                // 乐观锁
	Check         map[string]string      // Check 键名为约束名,键值为约束表达式
	Meta          map[string][]string    // 表级别的数据,如存储引擎,表名和字符集等。
	Constraints   map[string]ConType     // 约束名缓存
}

Model 表示一个数据库的表模型。数据结构从字段和字段的 struct tag 中分析得出。

func (*Model) FindColumn

func (m *Model) FindColumn(name string) *Column

FindColumn 查找指定名称的列

不存在该列则返回 nil

type Models

type Models struct {
	// contains filtered or unexported fields
}

Models 数据模型管理

func NewModels

func NewModels() *Models

NewModels 声明 Models 变量

func (*Models) Clear

func (ms *Models) Clear()

Clear 清除所有的 Model 缓存。

func (*Models) New

func (ms *Models) New(obj interface{}) (*Model, error)

New 从一个 obj 声明一个 Model 实例。 obj 可以是一个 struct 实例或是指针。

Jump to

Keyboard shortcuts

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