Documentation ¶
Index ¶
- Constants
- func ForeignKey(symbol string) *foreignKeyBuilder
- func ForeignKeyFromDef(def ForeignKeyDef) *foreignKeyBuilder
- func Index(name string) *indexBuilder
- func IndexFromDef(e IndexDef) *indexBuilder
- func PkgName(path string) string
- func PkgQualifier(ident string) string
- func TagName(kind, name string) string
- type ColumnDef
- type EntityBuilder
- func (self *EntityBuilder) Build(opt *Option) *EntityDescriptor
- func (self *EntityBuilder) Fields() []Fielder
- func (self *EntityBuilder) ForeignKeys() []ForeignKeyer
- func (self *EntityBuilder) Indexes() []Indexer
- func (self *EntityBuilder) Metadata() (name, comment string)
- func (self *EntityBuilder) SetFields(fields ...Fielder) *EntityBuilder
- func (self *EntityBuilder) SetForeignKeys(fks ...ForeignKeyer) *EntityBuilder
- func (self *EntityBuilder) SetIndexes(indexes ...Indexer) *EntityBuilder
- func (self *EntityBuilder) SetMetadata(name, comment string) *EntityBuilder
- func (self *EntityBuilder) SetTable(tb TableDef) *EntityBuilder
- func (self *EntityBuilder) Table() TableDef
- type EntityDescriptor
- type EntityDescriptorSlice
- type FieldBuilder
- func Bool(name string) *FieldBuilder
- func Bytes(name string) *FieldBuilder
- func Enum(name string) *FieldBuilder
- func Field(t *GoType, name string) *FieldBuilder
- func FieldFromDef(t *GoType, def ColumnDef) *FieldBuilder
- func Float32(name string) *FieldBuilder
- func Float64(name string) *FieldBuilder
- func Int(name string) *FieldBuilder
- func Int16(name string) *FieldBuilder
- func Int32(name string) *FieldBuilder
- func Int64(name string) *FieldBuilder
- func Int8(name string) *FieldBuilder
- func JSON(name string) *FieldBuilder
- func String(name string) *FieldBuilder
- func Time(name string) *FieldBuilder
- func UUID(name string, typ driver.Valuer) *FieldBuilder
- func Uint(name string) *FieldBuilder
- func Uint16(name string) *FieldBuilder
- func Uint32(name string) *FieldBuilder
- func Uint64(name string) *FieldBuilder
- func Uint8(name string) *FieldBuilder
- func (b *FieldBuilder) Build(opt *Option) *FieldDescriptor
- func (b *FieldBuilder) Column(e ColumnDef) *FieldBuilder
- func (b *FieldBuilder) Comment(c string) *FieldBuilder
- func (b *FieldBuilder) GoType(typ any) *FieldBuilder
- func (b *FieldBuilder) Nullable() *FieldBuilder
- func (b *FieldBuilder) Optional() *FieldBuilder
- func (b *FieldBuilder) Tags(tags ...string) *FieldBuilder
- type FieldDescriptor
- type Fielder
- type ForeignKeyDef
- type ForeignKeyDescriptor
- type ForeignKeyer
- type GoType
- func BoolType() *GoType
- func BytesType() *GoType
- func DatatypesDateType() *GoType
- func DatatypesJSONType() *GoType
- func DecimalType() *GoType
- func EnumType() *GoType
- func Float32Type() *GoType
- func Float64Type() *GoType
- func Int16Type() *GoType
- func Int32Type() *GoType
- func Int64Type() *GoType
- func Int8Type() *GoType
- func IntType() *GoType
- func JSONRawMessageType() *GoType
- func NewGoType(t Type, v any) *GoType
- func SQLNullBoolType() *GoType
- func SQLNullByteType() *GoType
- func SQLNullFloat64Type() *GoType
- func SQLNullInt16Type() *GoType
- func SQLNullInt32Type() *GoType
- func SQLNullInt64Type() *GoType
- func SQLNullStringType() *GoType
- func SQLNullTimeType() *GoType
- func SoftDeleteType() *GoType
- func StringType() *GoType
- func TimeType() *GoType
- func Uint16Type() *GoType
- func Uint32Type() *GoType
- func Uint64Type() *GoType
- func Uint8Type() *GoType
- func UintType() *GoType
- type IndexDef
- type IndexDescriptor
- type Indexer
- type MixinEntity
- type MixinSchema
- type Option
- type ProtoMessage
- type Schema
- type Schemaer
- type TableDef
- type Type
Constants ¶
const ( TagSmallCamelCase = "smallCamelCase" TagCamelCase = "camelCase" TagSnakeCase = "snakeCase" TagKebab = "kebab" )
Variables ¶
This section is empty.
Functions ¶
func ForeignKey ¶
func ForeignKey(symbol string) *foreignKeyBuilder
ForeignKeyFromDef returns a new ForeignKey with the ForeignKeyDef.
func ForeignKeyFromDef ¶
func ForeignKeyFromDef(def ForeignKeyDef) *foreignKeyBuilder
ForeignKeyFromDef returns a new ForeignKey with the ForeignKeyDef.
func IndexFromDef ¶
func IndexFromDef(e IndexDef) *indexBuilder
IndexFromDef returns a new Index with the IndexDef. auto set name, fields, index.
func PkgName ¶
PkgName returns the package name from a Go path with a package qualifier. github.com/things/ens -> ens
func PkgQualifier ¶
PkgQualifier returns the package name from a Go identifier with a package qualifier. eg. time.Time -> time
Types ¶
type EntityBuilder ¶
type EntityBuilder struct {
// contains filtered or unexported fields
}
func EntityFromDef ¶
func EntityFromDef(def TableDef) *EntityBuilder
EntityFromDef returns a new entity with the TableDef. auto set name, comment, table.
func (*EntityBuilder) Build ¶ added in v0.2.1
func (self *EntityBuilder) Build(opt *Option) *EntityDescriptor
func (*EntityBuilder) Fields ¶
func (self *EntityBuilder) Fields() []Fielder
func (*EntityBuilder) ForeignKeys ¶
func (self *EntityBuilder) ForeignKeys() []ForeignKeyer
func (*EntityBuilder) Indexes ¶
func (self *EntityBuilder) Indexes() []Indexer
func (*EntityBuilder) Metadata ¶
func (self *EntityBuilder) Metadata() (name, comment string)
func (*EntityBuilder) SetFields ¶
func (self *EntityBuilder) SetFields(fields ...Fielder) *EntityBuilder
func (*EntityBuilder) SetForeignKeys ¶
func (self *EntityBuilder) SetForeignKeys(fks ...ForeignKeyer) *EntityBuilder
func (*EntityBuilder) SetIndexes ¶
func (self *EntityBuilder) SetIndexes(indexes ...Indexer) *EntityBuilder
func (*EntityBuilder) SetMetadata ¶
func (self *EntityBuilder) SetMetadata(name, comment string) *EntityBuilder
func (*EntityBuilder) SetTable ¶
func (self *EntityBuilder) SetTable(tb TableDef) *EntityBuilder
func (*EntityBuilder) Table ¶
func (self *EntityBuilder) Table() TableDef
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 ProtoMessage []*ProtoMessage // protobuf message information. }
EntityDescriptor Each table corresponds to an EntityDescriptor
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 FieldBuilder ¶ added in v0.16.0
type FieldBuilder struct {
// contains filtered or unexported fields
}
FieldBuilder is the builder for field.
func Bool ¶
func Bool(name string) *FieldBuilder
func Bytes ¶
func Bytes(name string) *FieldBuilder
func Enum ¶
func Enum(name string) *FieldBuilder
func Field ¶
func Field(t *GoType, name string) *FieldBuilder
Field returns a new Field with the type.
func FieldFromDef ¶
func FieldFromDef(t *GoType, def ColumnDef) *FieldBuilder
FieldFromDef returns a new Field with the type and ColumnDef. auto set name, comment, nullable, column and optional.
func Float32 ¶
func Float32(name string) *FieldBuilder
func Float64 ¶
func Float64(name string) *FieldBuilder
func Int ¶
func Int(name string) *FieldBuilder
func Int16 ¶
func Int16(name string) *FieldBuilder
func Int32 ¶
func Int32(name string) *FieldBuilder
func Int64 ¶
func Int64(name string) *FieldBuilder
func Int8 ¶
func Int8(name string) *FieldBuilder
func JSON ¶
func JSON(name string) *FieldBuilder
func String ¶
func String(name string) *FieldBuilder
func Time ¶
func Time(name string) *FieldBuilder
func Uint ¶
func Uint(name string) *FieldBuilder
func Uint16 ¶
func Uint16(name string) *FieldBuilder
func Uint32 ¶
func Uint32(name string) *FieldBuilder
func Uint64 ¶
func Uint64(name string) *FieldBuilder
func Uint8 ¶
func Uint8(name string) *FieldBuilder
func (*FieldBuilder) Build ¶ added in v0.16.0
func (b *FieldBuilder) Build(opt *Option) *FieldDescriptor
Build implements the Fielder interface by returning its descriptor.
func (*FieldBuilder) Column ¶ added in v0.16.0
func (b *FieldBuilder) Column(e ColumnDef) *FieldBuilder
Column the column expression of the field.
func (*FieldBuilder) Comment ¶ added in v0.16.0
func (b *FieldBuilder) Comment(c string) *FieldBuilder
Comment sets the comment of the field.
func (*FieldBuilder) GoType ¶ added in v0.16.0
func (b *FieldBuilder) GoType(typ any) *FieldBuilder
GoType overrides the default Go type with a custom one.
field.Bool("deleted"). GoType(sql.NullBool{}) field.Bytes("ip"). GoType(net.IP("127.0.0.1")) field.String("dir"). GoType(http.Dir("dir"))
func (*FieldBuilder) Nullable ¶ added in v0.16.0
func (b *FieldBuilder) Nullable() *FieldBuilder
Nullable indicates that this field is a nullable.
func (*FieldBuilder) Optional ¶ added in v0.16.0
func (b *FieldBuilder) Optional() *FieldBuilder
Optional indicates that this field is optional. Unlike "Nullable" only fields, "Optional" fields are pointers in the generated struct.
func (*FieldBuilder) Tags ¶ added in v0.16.0
func (b *FieldBuilder) Tags(tags ...string) *FieldBuilder
Tags adds a list of tags to the field tag.
type FieldDescriptor ¶
type FieldDescriptor struct { Name string // field name Comment string // field comment Nullable bool // Nullable reports whether the column may be null. Column ColumnDef // for go Type *GoType // go type information. Optional bool // nullable struct field. Tags []string // Tags struct tag RapierDataType string // rapier data type }
type Fielder ¶
type Fielder interface {
Build(*Option) *FieldDescriptor
}
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 ForeignKeyer ¶
type ForeignKeyer interface {
Build() *ForeignKeyDescriptor
}
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. Nullable bool // pointers or slices, means not need point. }
func DatatypesDateType ¶
func DatatypesDateType() *GoType
func DatatypesJSONType ¶
func DatatypesJSONType() *GoType
func DecimalType ¶
func DecimalType() *GoType
func Float32Type ¶
func Float32Type() *GoType
func Float64Type ¶
func Float64Type() *GoType
func JSONRawMessageType ¶
func JSONRawMessageType() *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 Uint16Type ¶
func Uint16Type() *GoType
func Uint32Type ¶
func Uint32Type() *GoType
func Uint64Type ¶
func Uint64Type() *GoType
func (*GoType) Comparable ¶
Comparable reports whether values of this type are comparable.
type IndexDescriptor ¶
type IndexDescriptor struct { Name string // index name Fields []string // field columns Index IndexDef }
IndexDescriptor
type Indexer ¶
type Indexer interface {
Build() *IndexDescriptor
}
type MixinEntity ¶
type MixinEntity interface { Metadata() (string, string) Table() TableDef Fields() []Fielder Indexes() []Indexer ForeignKeys() []ForeignKeyer Build(*Option) *EntityDescriptor }
func ParseModel ¶ added in v0.16.0
func ParseModel(v any) (MixinEntity, error)
type MixinSchema ¶
type MixinSchema struct { Name string // schema name Entities []MixinEntity // schema entity. }
MixinSchema information
func (*MixinSchema) Build ¶
func (self *MixinSchema) Build(opt *Option) *Schema
type Option ¶
type Option struct { EnableInt bool `yaml:"enableInt" json:"enableInt"` // 使能int8,uint8,int16,uint16,int32,uint32输出为int,uint EnableIntegerInt bool `yaml:"enableIntegerInt" json:"enableIntegerInt"` // 使能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标签列表, support smallCamelCase, camelCase, snakeCase, kebab EnableGogo bool `yaml:"enableGogo" json:"enableGogo"` // 使能用 gogo (仅输出 proto 有效) EnableSea bool `yaml:"enableSea" json:"enableSea"` // 使能用 seaql (仅输出 proto 有效)} }
type ProtoMessage ¶
type Schema ¶
type Schema struct { Name string // schema name Entities []*EntityDescriptor // schema entity. }
Schema
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.