Beego orm 模型字段與數據庫類型的對應

深度學習,ORM 推薦的對應數據庫類型,在此列出,自動建表功能也會以此爲標準。默認全部的字段都是 NOT NULL

MySQL

go
mysql
int, int32-設置auto或者名稱爲Id
integer AUTO_INCREMENT
int64-設置auto或者名稱爲Id
bigint AUTO_INCREMENT
uint, uint32 - 設置 auto 或者名稱爲 Id
integer unsigned AUTO_INCREMENT
uint64 - 設置 auto 或者名稱爲 Id
bigint unsigned AUTO_INCREMENT
bool
bool
string - 默認爲 size 255
varchar(size)
string - 設置 type(text)
longtext
time.Time-設置 type爲date
date
time.Time
datetime
byte
tinyint unsigned
rune
integer
int
integer
int8
tinyint
int16
smallint
int32
integer
int64
bigint
uint
integer unsigned
uint8
tinyint unsigned
uint16
smallint unsigned
uint32
integer unsigned
uint64
bigint unsigned
float32
double precision
float64
double precision
float64 設置digits,decimals
numeric(digits, decimals)
Sqlite3

go
sqlite3
int, int32, int64, uint, uint32, uint64 - 設置 auto 或者名稱爲 Id
integer AUTOINCREMENT
bool
bool
string - 默認爲 size 255
varchar(size)
string - 設置 type(text)
text
time.Time - 設置 type 爲 date
date
time.Time
datetime
byte
tinyint unsigned
rune
integer
int
integer
int8
tinyint
int16
smallint
int32
integer
int64
bigint
uint
integer unsigned
uint8
tinyint unsigned
uint16
smallint unsigned
uint32
integer unsigned
uint64
bigint unsigned
float32
real
float64
real
float64 設置digits,decimals
decimal
PostgreSQL
go
postgres
int, int32, int64, uint, uint32, uint64 - 設置 auto 或者名稱爲 Id
serial
bool
bool
string - 默認爲 size 255
varchar(size)
string - 設置 type(text)
text
time.Time - 設置 type 爲 date
date
time.Time
timestamp with time zone
byte
smallint CHECK(「column」 >= 0 AND 「column」 <= 255)
rune
integer
int
integer
int8
smallint CHECK(「column」 >= -127 AND 「column」 <= 128)
int16
smallint
int32
integer
int64
bigint
uint
bigint CHECK(「column」 >= 0)
uint8
smallint CHECK(「column」 >= 0 AND 「column」 <= 255)
uint16
integer CHECK(「column」 >= 0)
uint32
bigint CHECK(「column」 >= 0)
uint64
bigint CHECK(「column」 >= 0)
float32
double precision
float64
double precision
float64 - 設置 digits, decimals
numeric(digits, decimals)
關係型字段
    其字段類型取決於對應的主鍵。
    RelForeignKey
    RelOneToOne
    RelManyToMany
    RelReverseOne
    RelReverseMany
相關文章
相關標籤/搜索