1
0
mirror of https://github.com/astaxie/beego.git synced 2025-07-03 16:30:19 +00:00

orm now support custom builtin types as model struct field or query args fix #489

This commit is contained in:
slene
2014-03-13 23:31:47 +08:00
parent 769f7c751b
commit 95e67ba2c2
4 changed files with 165 additions and 70 deletions

View File

@ -99,34 +99,41 @@ func getColumnName(ft int, addrField reflect.Value, sf reflect.StructField, col
// return field type as type constant from reflect.Value
func getFieldType(val reflect.Value) (ft int, err error) {
elm := reflect.Indirect(val)
switch elm.Interface().(type) {
case int8:
switch elm.Kind() {
case reflect.Int8:
ft = TypeBitField
case int16:
case reflect.Int16:
ft = TypeSmallIntegerField
case int32, int:
case reflect.Int32, reflect.Int:
ft = TypeIntegerField
case int64, sql.NullInt64:
case reflect.Int64:
ft = TypeBigIntegerField
case uint8:
case reflect.Uint8:
ft = TypePositiveBitField
case uint16:
case reflect.Uint16:
ft = TypePositiveSmallIntegerField
case uint32, uint:
case reflect.Uint32, reflect.Uint:
ft = TypePositiveIntegerField
case uint64:
case reflect.Uint64:
ft = TypePositiveBigIntegerField
case float32, float64, sql.NullFloat64:
case reflect.Float32, reflect.Float64:
ft = TypeFloatField
case bool, sql.NullBool:
case reflect.Bool:
ft = TypeBooleanField
case string, sql.NullString:
case reflect.String:
ft = TypeCharField
default:
if elm.CanInterface() {
if _, ok := elm.Interface().(time.Time); ok {
ft = TypeDateTimeField
}
switch elm.Interface().(type) {
case sql.NullInt64:
ft = TypeBigIntegerField
case sql.NullFloat64:
ft = TypeFloatField
case sql.NullBool:
ft = TypeBooleanField
case sql.NullString:
ft = TypeCharField
case time.Time:
ft = TypeDateTimeField
}
}
if ft&IsFieldType == 0 {