ast

package
v0.0.1-rc13 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ColumnNameTpl = template.Must(template.New("columnNameTpl").Parse(columnNameTpl))
View Source
var HelperTpl = template.Must(template.New("helperTpl").Parse(helperTpl))
View Source
var ImportsHeads = map[string]string{
	"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

View Source
var TableNameTpl = template.Must(template.New("tableNameTpl").Parse(tableNameTpl))

Functions

This section is empty.

Types

type Field

type Field struct {
	FieldName      string              // field name
	FieldType      string              // field type
	FieldComment   string              // field comment
	FieldTags      map[string][]string // field tags
	ColumnDataType string              // field column go type.
	ColumnName     string              // field column name in database
}

Field of a struct

func (*Field) AddFieldTag

func (e *Field) AddFieldTag(k string, v string) *Field

AddFieldTag Add a tag

func (*Field) BuildLine

func (e *Field) BuildLine() string

BuildLine build a field line

func (*Field) RemoveFieldTag

func (e *Field) RemoveFieldTag(k, v string) *Field

type File

type File struct {
	Filename        string            // file name
	PackageName     string            // package name
	Imports         map[string]string // import package
	Structs         []Struct          // struct list
	IsOutColumnName bool              // 是否输出表的列名
}

File a file

func (*File) AddImport

func (p *File) AddImport(imp string) *File

AddImport Add import by type

func (*File) AddStruct

func (p *File) AddStruct(st Struct) *File

AddStruct Add a structure

func (*File) Build

func (p *File) Build() string

Build the file data

func (*File) BuildSQL

func (p *File) BuildSQL() string

Build all struct in one file

func (*File) SetOutColumnName

func (p *File) SetOutColumnName(b bool) *File

SetOutColumnName set out column name

type ProtobufField

type ProtobufField struct {
	ColumnComment  string
	ColumnDataType string
	ColumnName     string
	Annotation     string
}

type ProtobufMessage

type ProtobufMessage struct {
	StructName    string
	StructComment string
	TableName     string
	AbbrTableName string
	Fields        []ProtobufField
}

type Struct

type Struct struct {
	StructName     string  // struct name
	StructComment  string  // struct comment
	StructFields   []Field // struct field list
	TableName      string  // table name
	CreateTableSQL string  // create table SQL
}

Struct define a struct

func (*Struct) AddStructFields

func (s *Struct) AddStructFields(e ...Field) *Struct

AddStructFields Add one or more fields

func (*Struct) Build

func (s *Struct) Build() string

Build Get the struct data.

func (*Struct) BuildColumnNameTemplate

func (s *Struct) BuildColumnNameTemplate() string

func (*Struct) BuildProtobufTemple

func (s *Struct) BuildProtobufTemple() string

func (*Struct) BuildSQL

func (s *Struct) BuildSQL() string

func (*Struct) BuildTableNameTemplate

func (s *Struct) BuildTableNameTemplate() string

Jump to

Keyboard shortcuts

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