Documentation ¶
Index ¶
Constants ¶
const ( CommandNameModel = "gen:model" CommandNameService = "gen:service" )
const ( OptBaseDir = "base-dir" OptBaseDirDefault = "./" OptBaseDirDesc = "Application working directory" OptBaseDirShort = 'b' OptDsn = "dsn" OptDsnDesc = "Database source name for connection, e.g. root:pass@tcp(127.0.0.1:3306)/test" OptExport = "export" OptExportDesc = "Specify export names, split with comma" OptExportShort = 'e' OptModelPath = "model-path" OptModelPathDefault = "app/models" OptModelPathDesc = "Generated model files location" OptModelPathShort = 'm' OptOverride = "override" OptOverrideDesc = "Override existing files" OptPrefix = "prefix" OptPrefixDesc = "Prefix name for table" OptPrefixShort = 'p' OptTargetPath = "target-path" OptTargetPathDesc = "Generated files saved to" OptTargetPathShort = 't' )
Variables ¶
var ( RegexStartLetter = regexp.MustCompile(`^(\S)`) RegexStartWithUnderline = regexp.MustCompile(`^_+`) RegexMiddleWithUnderline = regexp.MustCompile(`_+(\S)`) RegexMatchUpperLetter = regexp.MustCompile(`([A-Z])`) RegexMatchManyUnderlines = regexp.MustCompile(`_+`) RegexMatchColumnExtraAutoIncrement = regexp.MustCompile(`auto_increment`) RegexMatchColumnType = regexp.MustCompile(`^([_a-zA-Z0-9]+)`) )
Functions ¶
This section is empty.
Types ¶
type Column ¶
type Column struct { Field ItemName `xorm:"Field"` Collation ItemCollation `xorm:"Collation"` Comment ItemComment `xorm:"Comment"` Type ColumnType `xorm:"Type"` Default ColumnDefault `xorm:"Default"` Key ColumnKey `xorm:"Key"` Null ColumnNull `xorm:"Null"` Extra ColumnExtra `xorm:"Extra"` // Related on table. Table *Table `xorm:"-"` // Info fields. CommentList []template.HTML `xorm:"-"` Datetime template.HTML `xorm:"-"` Script template.HTML `xorm:"-"` // Name and type fields. ExportName string `xorm:"-"` // for field name. e.g. Id, UserId etc ExportType string `xorm:"-"` // for field type. e.g. int, db.Date, db.Datetime etc ExportJson string `xorm:"-"` // for field tag. e.g. id, user_id etc ExportOrm string `xorm:"-"` // for field tag. e.g. id pk autoincr, user_id etc ExportPkg string `xorm:"-"` // for field tag. e.g. models, services etc IsDate bool `xorm:"-"` IsDatetime bool `xorm:"-"` IsDatetimeOnUpdate bool `xorm:"-"` IsPrimaryKey bool `xorm:"-"` }
Column is a component for table definition (DDL).
type ColumnDefault ¶
type ColumnDefault string
ColumnDefault is a type for field name of a table.
func (ColumnDefault) String ¶
func (o ColumnDefault) String() string
type ColumnExtra ¶
type ColumnExtra string
ColumnExtra is a type for field name of a table.
func (ColumnExtra) Convert ¶
func (o ColumnExtra) Convert(field ItemName) string
Convert field name to exported orm name.
.Convert("id") // return "id pk autoincr" .Convert("user_id") // return "user_id"
func (ColumnExtra) IsDatetimeOnUpdate ¶
func (o ColumnExtra) IsDatetimeOnUpdate() bool
func (ColumnExtra) String ¶
func (o ColumnExtra) String() string
type ColumnType ¶
type ColumnType string
ColumnType is a type for field name of a table.
func (ColumnType) IsDate ¶
func (o ColumnType) IsDate() bool
func (ColumnType) IsDatetime ¶
func (o ColumnType) IsDatetime() bool
func (ColumnType) Origin ¶
func (o ColumnType) Origin() string
func (ColumnType) String ¶
func (o ColumnType) String() string
type ItemComment ¶
type ItemComment string
ItemComment is a type for table and field name.
func (ItemComment) String ¶
func (o ItemComment) String() string
String returns a comment string without new line.
func (ItemComment) Strings ¶
func (o ItemComment) Strings() []string
Strings returns a comment string list with new line.
type ItemName ¶
type ItemName string
ItemName is a type for table and field name.
func (ItemName) Allow ¶
Allow return true if start with an a-z letter.
Output:
return true // user return false // _user
func (ItemName) FileName ¶
FileName convert to file name without extension name.
Rule:
- table name : `cdb_user_info`
- prefix : `cdb_`
- file name : `user_info`
Output:
return "user_info"
func (ItemName) String ¶
String returns the origin name with any formats.
Output:
return "user_info" return "UserInfo" return "userInfo"
func (ItemName) StructName ¶
StructName convert to struct name that starts with an upper-case letter.
Rule:
- table name : `cdb_user_info`
- prefix : `cdb_`
- struct name : `UserInfo`
Output:
return "UserInfo"
func (ItemName) ToLargeCamel ¶
ToLargeCamel returns a large camel that equals to struct name.
Output:
return "UserInfo"
func (ItemName) ToSmallCamel ¶
ToSmallCamel returns a small-camel format name.
Output:
return "userInfo"
type Table ¶
type Table struct { // Normal fields. Engine string `xorm:"Engine"` Format string `xorm:"Row_format"` Name ItemName `xorm:"Name"` Comment ItemComment `xorm:"Comment"` Collation ItemCollation `xorm:"Collation"` // Belongs to. Columns []*Column `xorm:"-"` PackageList []string PackageMapper map[string]bool // Info fields. CommentList []template.HTML `xorm:"-"` Datetime template.HTML `xorm:"-"` Script template.HTML `xorm:"-"` // Execution fields. ModelName string `xorm:"-"` ModelPkg string `xorm:"-"` ServiceName string `xorm:"-"` ServicePkg string `xorm:"-"` // Primary prop. PrimaryName string `xorm:"-"` PrimaryFieldName string `xorm:"-"` PrimaryType string `xorm:"-"` }
Table is a component for table definition (DDL).
type Target ¶
type Target string
Target is a type name for generated file path.
Example:
Target("/data/sketch/app/models/example.go") Target("/data/sketch/app/services/example_service.go")