Skip to main content
Version: 2.8.x(Latest)

When using GoFrame ORM to query data, since the field value is a generic object, the returned data type will be automatically recognized and mapped to the Go variable type as the concrete value of the generic.

For example:

  • When the field type is int(xx), the queried field value type will be recognized as int type
  • When the field type is varchar(xxx)/ char(xxx)/ text, etc., it will be automatically recognized as string type
  • ……

Taking mysql types as an example, the following introduces the automatic recognition and mapping relationship between database types and Go variable types:

tip

The version may be updated iteratively, please check the source code for details https://github.com/gogf/gf/blob/master/database/gdb/gdb_core_structure.go

Database TypeGo Variable Type
*charstring
*textstring
*binarybytes
*blobbytes
*intint
*moneyfloat64
bitint
big_intint64
floatfloat64
doublefloat64
decimalfloat64
boolbool
yeartime.Time
datetime.Time
datetimetime.Time
timetime.Time
timestamptime.Time
othersstring

This feature is especially friendly for encoding query results and directly returning them to the client via methods like JSON.