ast

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ImportsHeads = map[string]string{
	"time.Time":      `"time"`,
	"gorm.Model":     `"gorm.io/gorm"`,
	"fmt":            `"fmt"`,
	"datatypes.JSON": `"gorm.io/datatypes"`,
	"datatypes.Date": `"gorm.io/datatypes"`,
}

ImportsHeads import head options

Functions

func IntoImports added in v0.3.0

func IntoImports(s []*Struct) map[string]struct{}

Types

type Field

type Field struct {
	FieldName    string // field name
	FieldType    string // field type
	FieldTag     string // field tag merge from FieldTags
	FieldComment string // field comment
	IsNullable   bool   // field is null or not
	IsTimestamp  bool   // field Go Type is time.Time
	ColumnGoType string // field column go standard type, e.g. int, uint, float64 ...
	ColumnName   string // field column name in database.
	Type         string // field defined SQL, e.g. varchar(255) NOT NULL DEFAULT ”
	IsSkipColumn bool   // skip filed used for output column
	AssistType   string // field AssistType, e.g. Bool, Uint32, Uint, Int
}

Field of a struct

  FieldName  FieldType  FieldTags                               FieldComment

	 |        |            |                                         |
     v        v            v                                         v
	Foo      int      `json:"foo,omitempty yaml:"foo,omitempty"` // 我是一个注释

FieldTag

key   v1 sep v2 ...
 |     | |
 v     v v
json:"foo,omitempty"

type FieldTagValues added in v0.3.0

type FieldTagValues struct {
	Separate string   // tag separate like [",", ";", " "]
	Value    []string // tag value
}

FieldTagValues field tag values

func NewFiledTagValues added in v0.3.0

func NewFiledTagValues() *FieldTagValues

NewFiledTagValues new FieldTagValues instance with default separate `,`.

func (*FieldTagValues) AddValue added in v0.3.0

func (f *FieldTagValues) AddValue(value string) *FieldTagValues

AddValue add value

func (*FieldTagValues) IsZero added in v0.3.0

func (f *FieldTagValues) IsZero() bool

IsZero value number is zero

func (*FieldTagValues) RemoveValue added in v0.3.0

func (f *FieldTagValues) RemoveValue(value string) *FieldTagValues

RemoveValue remove value

func (*FieldTagValues) SetSeparate added in v0.3.0

func (f *FieldTagValues) SetSeparate(separate string) *FieldTagValues

SetSeparate set separate.

type FieldTags added in v0.3.0

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

FieldTags contains multiple tags

key   v1 sep v2 ...
 |     | |
 v     v v
json:"foo,omitempty"

func NewFieldTags added in v0.3.0

func NewFieldTags() *FieldTags

func (*FieldTags) Add added in v0.3.0

func (f *FieldTags) Add(key string, tagValue *FieldTagValues) *FieldTags

Add add a tag.

func (*FieldTags) AddTagValue added in v0.3.0

func (f *FieldTags) AddTagValue(key, value string) *FieldTags

AddTagValue add a tag value

func (*FieldTags) Get added in v0.3.0

func (f *FieldTags) Get(key string) *FieldTagValues

Get get a tag.

func (*FieldTags) IntoFieldTag added in v0.3.0

func (f *FieldTags) IntoFieldTag() string

func (*FieldTags) Remove added in v0.3.0

func (f *FieldTags) Remove(key string) *FieldTags

Remove remove a tag.

func (*FieldTags) RemoveTagValue added in v0.3.0

func (f *FieldTags) RemoveTagValue(key, value string) *FieldTags

RemoveTagValue remove a tag value

func (*FieldTags) SetTagSeparate added in v0.3.0

func (f *FieldTags) SetTagSeparate(key, sep string) *FieldTags

SetTagSeparate set the tag separate

type File

type File struct {
	Version     string
	Filename    string              // file name
	PackageName string              // package name
	Imports     map[string]struct{} // import package
	Structs     []*Struct           // struct list in file
	// for other use, for example proto
	Package   string            // package
	Options   map[string]string // options
	HasColumn bool              // has column
}

File a file

type ProtobufMessageField

type ProtobufMessageField struct {
	FieldDataType   string // 列数据类型
	FieldName       string // 列名称
	FieldComment    string // 列注释
	FieldAnnotation string // 列注解
}

func ParseProtobuf added in v0.3.0

func ParseProtobuf(structFields []Field, enableGogo, enableSea bool) []ProtobufMessageField

type SqlFile added in v0.3.0

type SqlFile struct {
	Version string
	Tables  []TableAttribute
}

type Struct

type Struct struct {
	StructName     string  // struct name
	StructComment  string  // struct comment
	StructFields   []Field // struct field list
	TableName      string  // struct table name in database.
	CreateTableSQL string  // create table SQL
	// other used fields
	SeaIndexes         []string               // seasql indexes
	ProtoMessageFields []ProtobufMessageField // proto message field
}

Struct define a struct

type TableAttribute added in v0.3.0

type TableAttribute struct {
	Name           string // table name, 表名
	Comment        string // table comment, 表注释
	CreateTableSQL string // Create SQL statements, 创建表的sql语句
}

Jump to

Keyboard shortcuts

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