Documentation
¶
Index ¶
- Constants
- Variables
- func AddModelFields(mi *ModelInfo, ind reflect.Value, mName string, index []int)
- func CamelString(s string) string
- func GetFullName(typ reflect.Type) string
- func GetTableEngine(val reflect.Value) string
- func GetTableIndex(val reflect.Value) [][]string
- func GetTableName(val reflect.Value) string
- func GetTableUnique(val reflect.Value) [][]string
- func IsApplicableTableForDB(val reflect.Value, db string) bool
- func ParseStructTag(data string) (attrs map[string]bool, tags map[string]string)
- func SnakeString(s string) string
- func SnakeStringWithAcronym(s string) string
- type BigIntegerField
- type BooleanField
- type CharField
- type DateField
- type DateTimeField
- type FieldInfo
- type Fielder
- type Fields
- type FloatField
- type IntegerField
- type JSONField
- type JsonbField
- type ModelCache
- func (mc *ModelCache) All() map[string]*ModelInfo
- func (mc *ModelCache) AllOrdered() []*ModelInfo
- func (mc *ModelCache) Bootstrap()
- func (mc *ModelCache) Clean()
- func (mc *ModelCache) Empty() bool
- func (mc *ModelCache) Get(table string) (mi *ModelInfo, ok bool)
- func (mc *ModelCache) GetByFullName(name string) (mi *ModelInfo, ok bool)
- func (mc *ModelCache) GetByMd(md interface{}) (*ModelInfo, bool)
- func (mc *ModelCache) Register(prefixOrSuffixStr string, prefixOrSuffix bool, models ...interface{}) (err error)
- func (mc *ModelCache) Set(table string, mi *ModelInfo) *ModelInfo
- type ModelInfo
- type PositiveBigIntegerField
- func (e *PositiveBigIntegerField) FieldType() int
- func (e *PositiveBigIntegerField) RawValue() interface{}
- func (e *PositiveBigIntegerField) Set(d uint64)
- func (e *PositiveBigIntegerField) SetRaw(value interface{}) error
- func (e *PositiveBigIntegerField) String() string
- func (e PositiveBigIntegerField) Value() uint64
- type PositiveIntegerField
- func (e *PositiveIntegerField) FieldType() int
- func (e *PositiveIntegerField) RawValue() interface{}
- func (e *PositiveIntegerField) Set(d uint32)
- func (e *PositiveIntegerField) SetRaw(value interface{}) error
- func (e *PositiveIntegerField) String() string
- func (e PositiveIntegerField) Value() uint32
- type PositiveSmallIntegerField
- func (e *PositiveSmallIntegerField) FieldType() int
- func (e *PositiveSmallIntegerField) RawValue() interface{}
- func (e *PositiveSmallIntegerField) Set(d uint16)
- func (e *PositiveSmallIntegerField) SetRaw(value interface{}) error
- func (e *PositiveSmallIntegerField) String() string
- func (e PositiveSmallIntegerField) Value() uint16
- type SmallIntegerField
- type TextField
- type TimeField
Constants ¶
const ( TypeBooleanField = 1 << iota TypeVarCharField TypeCharField TypeTextField TypeTimeField TypeDateField TypeDateTimeField TypeBitField TypeSmallIntegerField TypeIntegerField TypeBigIntegerField TypePositiveBitField TypePositiveSmallIntegerField TypePositiveIntegerField TypePositiveBigIntegerField TypeFloatField TypeDecimalField TypeJSONField TypeJsonbField RelForeignKey RelOneToOne RelManyToMany RelReverseOne RelReverseMany )
Define the Type enum
const ( IsIntegerField = ^-TypePositiveBigIntegerField >> 6 << 7 IsPositiveIntegerField = ^-TypePositiveBigIntegerField >> 10 << 11 IsRelField = ^-RelReverseMany >> 18 << 19 IsFieldType = ^-RelReverseMany<<1 + 1 )
Define some logic enum
const ( OdCascade = "cascade" OdSetNULL = "set_null" OdSetDefault = "set_default" OdDoNothing = "do_nothing" )
Variables ¶
var ( NameStrategyMap = map[string]fn{ DefaultNameStrategy: SnakeString, SnakeAcronymNameStrategy: SnakeStringWithAcronym, } DefaultNameStrategy = "snakeString" SnakeAcronymNameStrategy = "snakeStringWithAcronym" NameStrategy = DefaultNameStrategy DefaultStructTagName = "orm" )
Functions ¶
func AddModelFields ¶
AddModelFields index: FieldByIndex returns the nested field corresponding to index
func GetFullName ¶
GetFullName get reflect.Type name with package path.
func GetTableEngine ¶
GetTableEngine get table engine, myisam or innodb.
func GetTableIndex ¶
GetTableIndex get table index from method.
func GetTableName ¶
GetTableName get struct table name. If the struct implement the TableName, then get the result as tablename else use the struct name which will apply snakeString.
func GetTableUnique ¶
GetTableUnique get table unique from method
func IsApplicableTableForDB ¶
IsApplicableTableForDB get whether the table needs to be created for the database alias
func ParseStructTag ¶
ParseStructTag parse struct tag string
func SnakeString ¶
SnakeString snake string, XxYy to xx_yy , XxYY to xx_y_y
func SnakeStringWithAcronym ¶
Types ¶
type BigIntegerField ¶
type BigIntegerField int64
BigIntegerField -9223372036854775808 to 9223372036854775807.
func (*BigIntegerField) FieldType ¶
func (e *BigIntegerField) FieldType() int
FieldType return enum type
func (*BigIntegerField) RawValue ¶
func (e *BigIntegerField) RawValue() interface{}
RawValue return BigIntegerField value
func (*BigIntegerField) SetRaw ¶
func (e *BigIntegerField) SetRaw(value interface{}) error
SetRaw convert interface int64/string to int64
func (*BigIntegerField) String ¶
func (e *BigIntegerField) String() string
String convert BigIntegerField to string
type BooleanField ¶
type BooleanField bool
BooleanField A true/false field.
func (*BooleanField) FieldType ¶
func (e *BooleanField) FieldType() int
FieldType return BooleanField the type
func (*BooleanField) RawValue ¶
func (e *BooleanField) RawValue() interface{}
RawValue return the current value
func (*BooleanField) SetRaw ¶
func (e *BooleanField) SetRaw(value interface{}) error
SetRaw set the interface to bool
func (*BooleanField) String ¶
func (e *BooleanField) String() string
String format the Bool to string
type CharField ¶
type CharField string
CharField A string field required values tag: size The size is enforced at the database level and in models’s validation. eg: `orm:"size(120)"`
func (*CharField) RawValue ¶
func (e *CharField) RawValue() interface{}
RawValue return the CharField value
type DateField ¶
DateField A date, represented in go by a time.Time instance. only date values like 2006-01-02 Has a few extra, optional attr tag:
auto_now: Automatically set the field to now every time the object is saved. Useful for “last-modified” timestamps. Note that the current date is always used; it’s not just a default value that you can override.
auto_now_add: Automatically set the field to now when the object is first created. Useful for creation of timestamps. Note that the current date is always used; it’s not just a default value that you can override.
eg: `orm:"auto_now"` or `orm:"auto_now_add"`
type DateTimeField ¶
DateTimeField A date, represented in go by a time.Time instance. datetime values like 2006-01-02 15:04:05 Takes the same extra arguments as DateField.
func (*DateTimeField) FieldType ¶
func (e *DateTimeField) FieldType() int
FieldType return the enum TypeDateTimeField
func (*DateTimeField) RawValue ¶
func (e *DateTimeField) RawValue() interface{}
RawValue return the datetime value
func (*DateTimeField) Set ¶
func (e *DateTimeField) Set(d time.Time)
Set set the time.Time to datetime
func (*DateTimeField) SetRaw ¶
func (e *DateTimeField) SetRaw(value interface{}) error
SetRaw convert the string or time.Time to DateTimeField
func (*DateTimeField) String ¶
func (e *DateTimeField) String() string
String return the time's String
func (DateTimeField) Value ¶
func (e DateTimeField) Value() time.Time
Value return the datetime value
type FieldInfo ¶
type FieldInfo struct { DBcol bool // table column fk and onetoone InModel bool Auto bool Pk bool Null bool Index bool Unique bool ColDefault bool // whether has default tag ToText bool AutoNow bool AutoNowAdd bool Rel bool // if type equal to RelForeignKey, RelOneToOne, RelManyToMany then true Reverse bool IsFielder bool // implement Fielder interface Mi *ModelInfo FieldIndex []int FieldType int Name string FullName string Column string AddrValue reflect.Value Sf reflect.StructField Initial utils.StrTo // store the default value Size int ReverseField string ReverseFieldInfo *FieldInfo ReverseFieldInfoTwo *FieldInfo ReverseFieldInfoM2M *FieldInfo RelTable string RelThrough string RelThroughModelInfo *ModelInfo RelModelInfo *ModelInfo Digits int Decimals int OnDelete string Description string TimePrecision *int DBType string }
FieldInfo single field info
func NewFieldInfo ¶
func NewFieldInfo(mi *ModelInfo, field reflect.Value, sf reflect.StructField, mName string) (fi *FieldInfo, err error)
NewFieldInfo new field info
type Fielder ¶
type Fielder interface { String() string FieldType() int SetRaw(interface{}) error RawValue() interface{} }
Fielder define field info
type Fields ¶
type Fields struct { Pk *FieldInfo Columns map[string]*FieldInfo Fields map[string]*FieldInfo FieldsLow map[string]*FieldInfo FieldsByType map[int][]*FieldInfo FieldsRel []*FieldInfo FieldsReverse []*FieldInfo FieldsDB []*FieldInfo Rels []*FieldInfo Orders []string DBcols []string }
Fields field info collection
func (*Fields) GetByColumn ¶
GetByColumn get field info by column name
type FloatField ¶
type FloatField float64
FloatField A floating-point number represented in go by a float32 value.
func (*FloatField) RawValue ¶
func (e *FloatField) RawValue() interface{}
RawValue return the FloatField value
func (*FloatField) SetRaw ¶
func (e *FloatField) SetRaw(value interface{}) error
SetRaw converter interface Float64 float32 or string to FloatField
type IntegerField ¶
type IntegerField int32
IntegerField -2147483648 to 2147483647
func (*IntegerField) FieldType ¶
func (e *IntegerField) FieldType() int
FieldType return the enum type
func (*IntegerField) RawValue ¶
func (e *IntegerField) RawValue() interface{}
RawValue return IntegerField value
func (*IntegerField) SetRaw ¶
func (e *IntegerField) SetRaw(value interface{}) error
SetRaw convert interface int32/string to int32
type JSONField ¶
type JSONField string
JSONField postgres json field.
func (*JSONField) RawValue ¶
func (j *JSONField) RawValue() interface{}
RawValue return JSONField value
type JsonbField ¶
type JsonbField string
JsonbField postgres json field.
func (*JsonbField) RawValue ¶
func (j *JsonbField) RawValue() interface{}
RawValue return JsonbField value
func (*JsonbField) SetRaw ¶
func (j *JsonbField) SetRaw(value interface{}) error
SetRaw convert interface string to string
func (*JsonbField) String ¶
func (j *JsonbField) String() string
String convert JsonbField to string
type ModelCache ¶
type ModelCache struct {
// contains filtered or unexported fields
}
ModelCache info collection
func NewModelCacheHandler ¶
func NewModelCacheHandler() *ModelCache
NewModelCacheHandler generator of ModelCache
func (*ModelCache) All ¶
func (mc *ModelCache) All() map[string]*ModelInfo
All return all model info
func (*ModelCache) AllOrdered ¶
func (mc *ModelCache) AllOrdered() []*ModelInfo
func (*ModelCache) Empty ¶
func (mc *ModelCache) Empty() bool
func (*ModelCache) Get ¶
func (mc *ModelCache) Get(table string) (mi *ModelInfo, ok bool)
Get model info by table name
func (*ModelCache) GetByFullName ¶
func (mc *ModelCache) GetByFullName(name string) (mi *ModelInfo, ok bool)
GetByFullName model info by full name
func (*ModelCache) GetByMd ¶
func (mc *ModelCache) GetByMd(md interface{}) (*ModelInfo, bool)
type ModelInfo ¶
type ModelInfo struct { Manual bool IsThrough bool Pkg string Name string FullName string Table string Model interface{} Fields *Fields AddrField reflect.Value // store the original struct value Uniques []string }
ModelInfo single model info
func NewM2MModelInfo ¶
NewM2MModelInfo combine related model info to new model info. prepare for relation models query.
func NewModelInfo ¶
NewModelInfo new model info
type PositiveBigIntegerField ¶
type PositiveBigIntegerField uint64
PositiveBigIntegerField 0 to 18446744073709551615
func (*PositiveBigIntegerField) FieldType ¶
func (e *PositiveBigIntegerField) FieldType() int
FieldType return enum type
func (*PositiveBigIntegerField) RawValue ¶
func (e *PositiveBigIntegerField) RawValue() interface{}
RawValue return PositiveBigIntegerField value
func (*PositiveBigIntegerField) Set ¶
func (e *PositiveBigIntegerField) Set(d uint64)
Set PositiveBigIntegerField value
func (*PositiveBigIntegerField) SetRaw ¶
func (e *PositiveBigIntegerField) SetRaw(value interface{}) error
SetRaw convert interface uint64/string to Uint64
func (*PositiveBigIntegerField) String ¶
func (e *PositiveBigIntegerField) String() string
String convert PositiveBigIntegerField to string
func (PositiveBigIntegerField) Value ¶
func (e PositiveBigIntegerField) Value() uint64
Value return uint64
type PositiveIntegerField ¶
type PositiveIntegerField uint32
PositiveIntegerField 0 to 4294967295
func (*PositiveIntegerField) FieldType ¶
func (e *PositiveIntegerField) FieldType() int
FieldType return enum type
func (*PositiveIntegerField) RawValue ¶
func (e *PositiveIntegerField) RawValue() interface{}
RawValue return the PositiveIntegerField Value
func (*PositiveIntegerField) Set ¶
func (e *PositiveIntegerField) Set(d uint32)
Set the PositiveIntegerField value
func (*PositiveIntegerField) SetRaw ¶
func (e *PositiveIntegerField) SetRaw(value interface{}) error
SetRaw convert interface uint32/string to Uint32
func (*PositiveIntegerField) String ¶
func (e *PositiveIntegerField) String() string
String convert PositiveIntegerField to string
func (PositiveIntegerField) Value ¶
func (e PositiveIntegerField) Value() uint32
Value return PositiveIntegerField value. Uint32
type PositiveSmallIntegerField ¶
type PositiveSmallIntegerField uint16
PositiveSmallIntegerField 0 to 65535
func (*PositiveSmallIntegerField) FieldType ¶
func (e *PositiveSmallIntegerField) FieldType() int
FieldType return enum type
func (*PositiveSmallIntegerField) RawValue ¶
func (e *PositiveSmallIntegerField) RawValue() interface{}
RawValue returns PositiveSmallIntegerField value
func (*PositiveSmallIntegerField) Set ¶
func (e *PositiveSmallIntegerField) Set(d uint16)
Set PositiveSmallIntegerField value
func (*PositiveSmallIntegerField) SetRaw ¶
func (e *PositiveSmallIntegerField) SetRaw(value interface{}) error
SetRaw convert Interface uint16/string to uint16
func (*PositiveSmallIntegerField) String ¶
func (e *PositiveSmallIntegerField) String() string
String convert uint16 to string
func (PositiveSmallIntegerField) Value ¶
func (e PositiveSmallIntegerField) Value() uint16
Value return uint16
type SmallIntegerField ¶
type SmallIntegerField int16
SmallIntegerField -32768 to 32767
func (*SmallIntegerField) FieldType ¶
func (e *SmallIntegerField) FieldType() int
FieldType return enum type SmallIntegerField
func (*SmallIntegerField) RawValue ¶
func (e *SmallIntegerField) RawValue() interface{}
RawValue return smallint value
func (*SmallIntegerField) Set ¶
func (e *SmallIntegerField) Set(d int16)
Set the SmallIntegerField value
func (*SmallIntegerField) SetRaw ¶
func (e *SmallIntegerField) SetRaw(value interface{}) error
SetRaw convert interface int16/string to int16
func (*SmallIntegerField) String ¶
func (e *SmallIntegerField) String() string
String convert smallint to string
type TextField ¶
type TextField string
TextField A large text field.
func (*TextField) RawValue ¶
func (e *TextField) RawValue() interface{}
RawValue return TextField value
type TimeField ¶
TimeField A time, represented in go by a time.Time instance. only time values like 10:00:00 Has a few extra, optional attr tag:
auto_now: Automatically set the field to now every time the object is saved. Useful for “last-modified” timestamps. Note that the current date is always used; it’s not just a default value that you can override.
auto_now_add: Automatically set the field to now when the object is first created. Useful for creation of timestamps. Note that the current date is always used; it’s not just a default value that you can override.
eg: `orm:"auto_now"` or `orm:"auto_now_add"`