load

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ImportPkgs 保存了导入的Go package路径。
	ImportPkgs []string = []string{}
)

Functions

This section is empty.

Types

type BuilderInfo

type BuilderInfo struct {
	// PkgPath 是加载的Schema包的Go package路径,之后会传给gen.Config。
	PkgPath string
	// Module 加载的entity package的模块信息。
	Module *packages.Module
	// Databases 从Schema中提取出的database的配置信息。
	// Config.Dbs中的只是获得数据库的名字和它拥有的entity。Databases获得的是完整的数据库配置信息。
	Databases []*Database
	// ExtraCodes Schema中不是数据库或者实体的代码。
	ExtraCodes []string
}

BuilderInfo 是一个用于生成代码的构建器, 包含了Schema的Go package路径和符合条件的database信息。

type Config

type Config struct {
	// Path 加载的Schema的路径。
	Path string
	// Entities 加载的Schema中拥有匿名字段[entity.Entity]的结构体的名称。
	Entities []string
	// BuildFlags 传递给go build的标志。
	BuildFlags []string
	// Dbs 加载的Schema中拥有匿名字段[entity.Database]的结构体的名称。
	Dbs []DbConfig
}

Config 用于从Schema中加载的所有database和entity的配置。

func (*Config) Load

func (c *Config) Load() (*BuilderInfo, error)

Load 加载Schema,并且利用这些信息生成一个Builder。

Returns:

0: 生成代码的构建器。
1: 错误信息。

ErrCodes:

  • Err_0100020004
  • Err_0100020005

type Database

type Database struct {
	// Name 数据库的名称。
	Name string
	// Tag 数据库的标签,开发者通过tag来实现数据库的连接和数据库实例的匹配。
	Tag string
	// Type 数据库类型。
	Type dialect.DbDriver
	// EntityMap 数据库中的entity的信息。
	EntityMap EntityMap
	// Entities 数据库中的entity的信息。
	Entities map[string]*Entity
}

Database 用户定义的Schema中已经处理好的database

func Unmarshal

func Unmarshal(b []byte) (*Database, error)

Unmarshal 实现了[entity.EntityInterface]的entity反序列化。

Params:

  • b: 序列化后的数据库信息。

Returns:

0: 反序列化后的Entity。

type DbConfig

type DbConfig struct {
	// Name 数据库名称。
	Name string
	// Entities 存储这个database所拥有的。
	Entities EntityMap
}

DbConfig 是一个包含了Schema的database的信息。

type Entity

type Entity struct {
	// Name entity的名称
	Name string `json:"name,omitempty"`
	// AttrName entity的属性名称
	AttrName string `json:"attr_name,omitempty"`
	// Comment entity的注释
	Comment string `json:"comment,omitempty"`
	// Config entity配置
	Config entity.EntityConfig `json:"config,omitempty"`
	// Fields entity的字段
	Fields []*Field `json:"fields,omitempty"`
	// ImportPkgs 导入的Go package路径
	ImportPkgs []string
	// Sequences entity的关联序列
	Sequences []entity.Sequence
	// Relations entity的关系
	Relations []*Relation
}

Entity 表示了从已经编译好的用户的package中加载的entity

func MarshalEntity

func MarshalEntity(ei entity.EntityInterface) (ent *Entity, err error)

MarshalEntity 将entity.EntityInterface序列化为Entity,用于生成代码。

Params:

  • ei: 实现了entity.EntityInterface的entity。

Returns:

0: 序列化后的Entity。

ErrCodes:

  • Err_0100020018

type EntityMap

type EntityMap map[string]string

EntityMap entity的key和类型。

和Config.Entities不同的是, EntityMap是用于记录database中的entity的信息, 而Config.Entities是用于记录entity结构体的名字。 例如:

type User struct {
	entity.Database
	User UserEntity
}
则这个EntityMap中的内容为:{
	"User": "UserEntity"
}

而Config.Entities中的内容为:["UserEntity"]

type ExeTmplConfig

type ExeTmplConfig struct {
	// Config 模版文件会匹配Config每个字段的值,例如[.Names]
	Config *Config
	// Package 模版文件会匹配[.Package]的值
	Package string
}

ExeTmplConfig 执行模板的配置。

type Field

type Field struct {
	entity.Descriptor
	// ValueType 字段的值在go中对应的类型,比如"entity.Int64"的ValueType为"int64"。
	ValueType string `json:"value_type,omitempty"`
	// Validators 字段的验证器数量
	Validators int `json:"validators,omitempty"`
	// StoragerType 字段的存储器的类型,这个是字段的作用是关联已经定义的好的存储器。比如field.IntStorage[int16]
	StoragerType string `json:"storager_type,omitempty"`
	// StoragerOrigType 字段的存储器去除泛型后的名字,比如field.IntStorage[int16]变成field.IntStorage
	StoragerOrigType string `json:"storager_orig_type,omitempty"`
	// StoragerPkg 字段的存储器的包路径
	StoragerPkg string `json:"storager_pkg,omitempty"`
}

Field 表示entity的字段所包含的信息。 继承了entity.Descriptor

type Relation added in v0.5.0

type Relation struct {
	// Desc entity在自定义时的信息
	Desc RelationDesc
	// Principal 主体实体
	Principal RelationEntity
	// Dependent 依赖实体
	Dependent RelationEntity
}

Relation 表示entity之间的关系

type RelationDesc added in v0.5.0

type RelationDesc struct {
	Has          Entity
	With         Entity
	HasRel       entity.Rel
	WithRel      entity.Rel
	ForeignKey   Field
	ReferenceKey Field
	Constraint   string
	Update       string
	Delete       string
}

RelationDesc 表示entity之间的关系的描述, 不用entity.RelationshipDescriptor是因为entity.RelationshipDescriptor有一些字段是接口类型, 在序列化时会产生异常。

type RelationEntity added in v0.5.0

type RelationEntity struct {
	Name string `json:"name,omitempty"`
	// AttrName entity的属性名称
	AttrName string `json:"attr_name,omitempty"`
	Field    *Field
	Rel      entity.Rel
}

RelationEntity 存储有关系的entity的信息

Jump to

Keyboard shortcuts

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