golang beego orm mysql sqlite3 postgresql 模型字段 数据库类型 对应关系

目录

MySQL

Sqlite3

PostgreSQL

关系型字段


在此列出 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,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)

关系型字段

其字段类型取决于对应的主键。

  • RelForeignKey
  • RelOnetoOne
  • RelManyToMany
  • RelReverSEOne
  • RelReverseMany

相关文章

功能概要:(目前已实现功能)公共展示部分:1.网站首页展示...
大体上把Python中的数据类型分为如下几类: Number(数字) ...
开发之前第一步,就是构造整个的项目结构。这就好比作一幅画...
源码编译方式安装Apache首先下载Apache源码压缩包,地址为ht...
前面说完了此项目的创建及数据模型设计的过程。如果未看过,...
python中常用的写爬虫的库有urllib2、requests,对于大多数比...