ens

package module
v1.0.0-rc1 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: MIT Imports: 21 Imported by: 4

README

ens

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CodeGen

type CodeGen struct {
	Entities          []*EntityDescriptor
	ByName            string
	Version           string
	PackageName       string
	DisableDocComment bool
	Option
	// contains filtered or unexported fields
}

func (*CodeGen) Bytes

func (g *CodeGen) Bytes() []byte

Bytes returns the CodeBuf's buffer.

func (*CodeGen) FormatSource

func (g *CodeGen) FormatSource() ([]byte, error)

FormatSource return formats and adjusts imports contents of the CodeGen's buffer.

func (*CodeGen) Gen

func (g *CodeGen) Gen() *CodeGen

func (*CodeGen) Print

func (g *CodeGen) Print(a ...any) (n int, err error)

Print formats using the default formats for its operands and writes to the generated output. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.

func (*CodeGen) Printf

func (g *CodeGen) Printf(format string, a ...any) (n int, err error)

Printf formats according to a format specifier for its operands and writes to the generated output. It returns the number of bytes written and any write error encountered.

func (*CodeGen) Println

func (g *CodeGen) Println(a ...any) (n int, err error)

Fprintln formats using the default formats to the generated output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

func (*CodeGen) Write

func (g *CodeGen) Write(b []byte) (n int, err error)

Write appends the contents of p to the buffer,

type ColumnDef

type ColumnDef interface {
	Column() *schema.Column
	Definition() string
	GormTag(*schema.Table) string
}

type EntityDescriptor

type EntityDescriptor struct {
	Name        string                  // entity name
	Comment     string                  // entity comment
	Table       TableDef                // entity table define
	Fields      []*FieldDescriptor      // field information
	Indexes     []*IndexDescriptor      // index information
	ForeignKeys []*ForeignKeyDescriptor // foreign key information
}

EntityDescriptor Each table corresponds to an EntityDescriptor

func ParseModel added in v0.16.0

func ParseModel(v any) (*EntityDescriptor, error)

func (*EntityDescriptor) IntoProto

func (s *EntityDescriptor) IntoProto() *proto.Message

func (*EntityDescriptor) IntoRapier

func (s *EntityDescriptor) IntoRapier() *rapier.Struct

func (*EntityDescriptor) IntoSQL

func (s *EntityDescriptor) IntoSQL() *sqlx.Table

type EntityDescriptorSlice

type EntityDescriptorSlice []*EntityDescriptor

func (EntityDescriptorSlice) Len

func (t EntityDescriptorSlice) Len() int

func (EntityDescriptorSlice) Less

func (t EntityDescriptorSlice) Less(i, j int) bool

func (EntityDescriptorSlice) Swap

func (t EntityDescriptorSlice) Swap(i, j int)

type FieldDescriptor

type FieldDescriptor struct {
	ColumnName string // 列名, snake case
	Comment    string // 注释
	Nullable   bool   // Nullable reports whether the column may be null.
	Column     ColumnDef
	// for go
	Type      GoType   // go type information.
	GoName    string   // Go name
	GoPointer bool     // go field is pointer.
	Tags      []string // Tags struct tag
}

func (*FieldDescriptor) GoType

func (field *FieldDescriptor) GoType(typ any)

func (*FieldDescriptor) IntoProto

func (field *FieldDescriptor) IntoProto() *proto.MessageField

func (*FieldDescriptor) IntoRapier

func (field *FieldDescriptor) IntoRapier() *rapier.StructField

type ForeignKeyDef

type ForeignKeyDef interface {
	ForeignKey() *schema.ForeignKey
	Definition() string
}

type ForeignKeyDescriptor

type ForeignKeyDescriptor struct {
	Symbol     string
	Table      string
	Columns    []string
	RefTable   string
	RefColumns []string
	OnUpdate   schema.ReferenceOption
	OnDelete   schema.ReferenceOption
	ForeignKey ForeignKeyDef
}

type GoType

type GoType struct {
	Type         Type   // Type enum.
	Ident        string // Type identifier,  e.g. int, time.Time, sql.NullInt64.
	PkgPath      string // import path. e.g. "", time, database/sql.
	PkgQualifier string // a package qualifier. e.g. "", time, sql.
	NoPointer    bool   // pointers or slices, means not need pointer.
}

func BoolType

func BoolType() GoType

func BytesType

func BytesType() GoType

func DatatypesDateType

func DatatypesDateType() GoType

func DatatypesJSONType

func DatatypesJSONType() GoType

func DecimalType

func DecimalType() GoType

func EnumType

func EnumType() GoType

func Float32Type

func Float32Type() GoType

func Float64Type

func Float64Type() GoType

func GormDeletedAtType

func GormDeletedAtType() GoType

func Int16Type

func Int16Type() GoType

func Int32Type

func Int32Type() GoType

func Int64Type

func Int64Type() GoType

func Int8Type

func Int8Type() GoType

func IntType

func IntType() GoType

func JSONRawMessageType

func JSONRawMessageType() GoType

func NewGoType

func NewGoType(t Type, v any) GoType

func SQLNullBoolType

func SQLNullBoolType() GoType

func SQLNullByteType

func SQLNullByteType() GoType

func SQLNullFloat64Type

func SQLNullFloat64Type() GoType

func SQLNullInt16Type

func SQLNullInt16Type() GoType

func SQLNullInt32Type

func SQLNullInt32Type() GoType

func SQLNullInt64Type

func SQLNullInt64Type() GoType

func SQLNullStringType

func SQLNullStringType() GoType

func SQLNullTimeType

func SQLNullTimeType() GoType

func SoftDeleteType

func SoftDeleteType() GoType

func StringType

func StringType() GoType

func TimeType

func TimeType() GoType

func Uint16Type

func Uint16Type() GoType

func Uint32Type

func Uint32Type() GoType

func Uint64Type

func Uint64Type() GoType

func Uint8Type

func Uint8Type() GoType

func UintType

func UintType() GoType

func (*GoType) Clone

func (t *GoType) Clone() GoType

func (*GoType) Comparable

func (t *GoType) Comparable() bool

Comparable reports whether values of this type are comparable.

func (*GoType) IsBool

func (t *GoType) IsBool() bool

IsBool reports if the given type is an bool type.

func (*GoType) IsFloat

func (t *GoType) IsFloat() bool

IsFloat reports if the given type is a float type.

func (*GoType) IsInteger

func (t *GoType) IsInteger() bool

IsInteger reports if the given type is an integral type.

func (*GoType) IsNumeric

func (t *GoType) IsNumeric() bool

IsNumeric reports if the given type is a numeric type.

func (*GoType) IsTime

func (t *GoType) IsTime() bool

IsTime reports if the given type is an time.Time type.

func (*GoType) IsValid

func (t *GoType) IsValid() bool

IsValid reports if the given type if known type.

func (*GoType) String

func (t *GoType) String() string

String returns the string representation of a type.

func (GoType) WithNewType

func (t GoType) WithNewType(tp Type) GoType

type IndexDef

type IndexDef interface {
	Index() *schema.Index
	Definition() string
}

type IndexDescriptor

type IndexDescriptor struct {
	Name   string   // index name
	Fields []string // field columns
	Index  IndexDef
}

IndexDescriptor

type Option

type Option struct {
	EnableInt          bool              `yaml:"enableInt" json:"enableInt"`                   // 使能int8,uint8,int16,uint16,int32,uint32输出为int,uint
	EnableBoolInt      bool              `yaml:"enableBoolInt" json:"enableBoolInt"`           // 使能bool输出int
	DisableNullToPoint bool              `yaml:"disableNullToPoint" json:"disableNullToPoint"` // 禁用字段为null时输出指针类型,将输出为sql.Nullxx
	EnableForeignKey   bool              `yaml:"enableForeignKey" json:"enableForeignKey"`     // 输出外键
	Tags               map[string]string `yaml:"tags" json:"tags"`                             // tags标签列表, 如 json: snakeCase, support smallCamelCase, camelCase, snakeCase, kebab
	EscapeName         []string          `yaml:"escapeName" json:"escapeName"`                 // 需要转义的字段
}

type Schema

type Schema struct {
	Name     string              // schema name
	Entities []*EntityDescriptor // schema entity.
}

Schema

func (*Schema) IntoProto

func (s *Schema) IntoProto() *proto.Schema

func (*Schema) IntoRapier

func (s *Schema) IntoRapier() *rapier.Schema

func (*Schema) IntoSQL

func (s *Schema) IntoSQL() *sqlx.Schema

type TableDef

type TableDef interface {
	Table() *schema.Table
	Definition() string
	PrimaryKey() IndexDef
}

type Type

type Type uint8

A Type represents a field type.

const (
	TypeInvalid Type = iota
	TypeBool
	TypeInt8
	TypeInt16
	TypeInt32
	TypeInt64
	TypeInt
	TypeUint8
	TypeUint16
	TypeUint32
	TypeUint64
	TypeUint
	TypeFloat32
	TypeFloat64
	TypeDecimal
	TypeString
	TypeEnum
	TypeBytes
	TypeTime
	TypeJSON
	TypeUUID
	TypeOther
)

List of field types.

func (Type) IntoProtoKind

func (t Type) IntoProtoKind() (k protoreflect.Kind, n string)

func (Type) IntoRapierType

func (t Type) IntoRapierType() rapier.Type

func (Type) IsBool

func (t Type) IsBool() bool

IsBool reports if the given type is an bool type.

func (Type) IsFloat

func (t Type) IsFloat() bool

IsFloat reports if the given type is a float type.

func (Type) IsInteger

func (t Type) IsInteger() bool

IsInteger reports if the given type is an integral type.

func (Type) IsNumeric

func (t Type) IsNumeric() bool

IsNumeric reports if the given type is a numeric type.

func (Type) IsTime

func (t Type) IsTime() bool

IsTime reports if the given type is an time.Time type.

func (Type) IsValid

func (t Type) IsValid() bool

IsValid reports if the given type if known type.

func (Type) String

func (t Type) String() string

String returns the string representation of a type.

Directories

Path Synopsis
cmd
ormat Module
internal

Jump to

Keyboard shortcuts

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