mirror of
https://github.com/astaxie/beego.git
synced 2025-07-03 17:20:18 +00:00
orm add full regular go type support, such as int8, uint8, byte, rune. add date/datetime timezone support very well.
This commit is contained in:
@ -6,11 +6,60 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
// _ "github.com/bylevel/pq"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
_ "github.com/lib/pq"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
type Data struct {
|
||||
Id int `orm:"auto"`
|
||||
Boolean bool
|
||||
Char string `orm:"size(50)"`
|
||||
Text string
|
||||
Date time.Time `orm:"type(date)"`
|
||||
DateTime time.Time
|
||||
Byte byte
|
||||
Rune rune
|
||||
Int int
|
||||
Int8 int8
|
||||
Int16 int16
|
||||
Int32 int32
|
||||
Int64 int64
|
||||
Uint uint
|
||||
Uint8 uint8
|
||||
Uint16 uint16
|
||||
Uint32 uint32
|
||||
Uint64 uint64
|
||||
Float32 float32
|
||||
Float64 float64
|
||||
Decimal float64 `orm:"digits(8);decimals(4)"`
|
||||
}
|
||||
|
||||
type DataNull struct {
|
||||
Id int `orm:"auto"`
|
||||
Boolean bool `orm:"null"`
|
||||
Char string `orm:"size(50);null"`
|
||||
Text string `orm:"null"`
|
||||
Date time.Time `orm:"type(date);null"`
|
||||
DateTime time.Time `orm:"null"`
|
||||
Byte byte `orm:"null"`
|
||||
Rune rune `orm:"null"`
|
||||
Int int `orm:"null"`
|
||||
Int8 int8 `orm:"null"`
|
||||
Int16 int16 `orm:"null"`
|
||||
Int32 int32 `orm:"null"`
|
||||
Int64 int64 `orm:"null"`
|
||||
Uint uint `orm:"null"`
|
||||
Uint8 uint8 `orm:"null"`
|
||||
Uint16 uint16 `orm:"null"`
|
||||
Uint32 uint32 `orm:"null"`
|
||||
Uint64 uint64 `orm:"null"`
|
||||
Float32 float32 `orm:"null"`
|
||||
Float64 float64 `orm:"null"`
|
||||
Decimal float64 `orm:"digits(8);decimals(4);null"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
Id int `orm:"auto"`
|
||||
UserName string `orm:"size(30);unique"`
|
||||
@ -111,6 +160,8 @@ var initSQLs = map[string]string{
|
||||
"DROP TABLE IF EXISTS `tag`;\n" +
|
||||
"DROP TABLE IF EXISTS `post_tags`;\n" +
|
||||
"DROP TABLE IF EXISTS `comment`;\n" +
|
||||
"DROP TABLE IF EXISTS `data`;\n" +
|
||||
"DROP TABLE IF EXISTS `data_null`;\n" +
|
||||
"CREATE TABLE `user_profile` (\n" +
|
||||
" `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,\n" +
|
||||
" `age` smallint NOT NULL,\n" +
|
||||
@ -153,6 +204,52 @@ var initSQLs = map[string]string{
|
||||
" `parent_id` integer,\n" +
|
||||
" `created` datetime NOT NULL\n" +
|
||||
") ENGINE=INNODB;\n" +
|
||||
"CREATE TABLE `data` (\n" +
|
||||
" `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,\n" +
|
||||
" `boolean` bool NOT NULL,\n" +
|
||||
" `char` varchar(50) NOT NULL,\n" +
|
||||
" `text` longtext NOT NULL,\n" +
|
||||
" `date` date NOT NULL,\n" +
|
||||
" `date_time` datetime NOT NULL,\n" +
|
||||
" `byte` tinyint unsigned NOT NULL,\n" +
|
||||
" `rune` integer NOT NULL,\n" +
|
||||
" `int` integer NOT NULL,\n" +
|
||||
" `int8` tinyint NOT NULL,\n" +
|
||||
" `int16` smallint NOT NULL,\n" +
|
||||
" `int32` integer NOT NULL,\n" +
|
||||
" `int64` bigint NOT NULL,\n" +
|
||||
" `uint` integer unsigned NOT NULL,\n" +
|
||||
" `uint8` tinyint unsigned NULL,\n" +
|
||||
" `uint16` smallint unsigned NOT NULL,\n" +
|
||||
" `uint32` integer unsigned NOT NULL,\n" +
|
||||
" `uint64` bigint unsigned NOT NULL,\n" +
|
||||
" `float32` double precision NOT NULL,\n" +
|
||||
" `float64` double precision NOT NULL,\n" +
|
||||
" `decimal` numeric(8,4) NOT NULL\n" +
|
||||
") ENGINE=INNODB;\n" +
|
||||
"CREATE TABLE `data_null` (\n" +
|
||||
" `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,\n" +
|
||||
" `boolean` bool,\n" +
|
||||
" `char` varchar(50),\n" +
|
||||
" `text` longtext,\n" +
|
||||
" `date` date,\n" +
|
||||
" `date_time` datetime,\n" +
|
||||
" `byte` tinyint unsigned,\n" +
|
||||
" `rune` integer,\n" +
|
||||
" `int` integer,\n" +
|
||||
" `int8` tinyint,\n" +
|
||||
" `int16` smallint,\n" +
|
||||
" `int32` integer,\n" +
|
||||
" `int64` bigint,\n" +
|
||||
" `uint` integer unsigned,\n" +
|
||||
" `uint8` tinyint unsigned,\n" +
|
||||
" `uint16` smallint unsigned,\n" +
|
||||
" `uint32` integer unsigned,\n" +
|
||||
" `uint64` bigint unsigned,\n" +
|
||||
" `float32` double precision,\n" +
|
||||
" `float64` double precision,\n" +
|
||||
" `decimal` numeric(8,4)\n" +
|
||||
") ENGINE=INNODB;\n" +
|
||||
"CREATE INDEX `user_141c6eec` ON `user` (`profile_id`);\n" +
|
||||
"CREATE INDEX `post_fbfc09f1` ON `post` (`user_id`);\n" +
|
||||
"CREATE INDEX `comment_699ae8ca` ON `comment` (`post_id`);\n" +
|
||||
@ -165,6 +262,8 @@ DROP TABLE IF EXISTS "post";
|
||||
DROP TABLE IF EXISTS "tag";
|
||||
DROP TABLE IF EXISTS "post_tags";
|
||||
DROP TABLE IF EXISTS "comment";
|
||||
DROP TABLE IF EXISTS "data";
|
||||
DROP TABLE IF EXISTS "data_null";
|
||||
CREATE TABLE "user_profile" (
|
||||
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"age" smallint NOT NULL,
|
||||
@ -207,6 +306,52 @@ CREATE TABLE "comment" (
|
||||
"parent_id" integer,
|
||||
"created" datetime NOT NULL
|
||||
);
|
||||
CREATE TABLE "data" (
|
||||
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"boolean" bool NOT NULL,
|
||||
"char" varchar(50) NOT NULL,
|
||||
"text" text NOT NULL,
|
||||
"date" date NOT NULL,
|
||||
"date_time" datetime NOT NULL,
|
||||
"byte" tinyint unsigned NOT NULL,
|
||||
"rune" integer NOT NULL,
|
||||
"int" integer NOT NULL,
|
||||
"int8" tinyint NOT NULL,
|
||||
"int16" smallint NOT NULL,
|
||||
"int32" integer NOT NULL,
|
||||
"int64" bigint NOT NULL,
|
||||
"uint" integer unsigned NOT NULL,
|
||||
"uint8" tinyint unsigned NOT NULL,
|
||||
"uint16" smallint unsigned NOT NULL,
|
||||
"uint32" integer unsigned NOT NULL,
|
||||
"uint64" bigint unsigned NOT NULL,
|
||||
"float32" real NOT NULL,
|
||||
"float64" real NOT NULL,
|
||||
"decimal" decimal
|
||||
);
|
||||
CREATE TABLE "data_null" (
|
||||
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"boolean" bool,
|
||||
"char" varchar(50),
|
||||
"text" text,
|
||||
"date" date,
|
||||
"date_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,
|
||||
"decimal" decimal
|
||||
);
|
||||
CREATE INDEX "user_141c6eec" ON "user" ("profile_id");
|
||||
CREATE INDEX "post_fbfc09f1" ON "post" ("user_id");
|
||||
CREATE INDEX "comment_699ae8ca" ON "comment" ("post_id");
|
||||
@ -220,6 +365,8 @@ DROP TABLE IF EXISTS "post";
|
||||
DROP TABLE IF EXISTS "tag";
|
||||
DROP TABLE IF EXISTS "post_tags";
|
||||
DROP TABLE IF EXISTS "comment";
|
||||
DROP TABLE IF EXISTS "data";
|
||||
DROP TABLE IF EXISTS "data_null";
|
||||
CREATE TABLE "user_profile" (
|
||||
"id" serial NOT NULL PRIMARY KEY,
|
||||
"age" smallint NOT NULL,
|
||||
@ -262,6 +409,52 @@ CREATE TABLE "comment" (
|
||||
"parent_id" integer,
|
||||
"created" timestamp with time zone NOT NULL
|
||||
);
|
||||
CREATE TABLE "data" (
|
||||
"id" serial NOT NULL PRIMARY KEY,
|
||||
"boolean" bool NOT NULL,
|
||||
"char" varchar(50) NOT NULL,
|
||||
"text" text NOT NULL,
|
||||
"date" date NOT NULL,
|
||||
"date_time" timestamp with time zone NOT NULL,
|
||||
"byte" smallint CHECK("byte" >= 0 AND "byte" <= 255) NOT NULL,
|
||||
"rune" integer NOT NULL,
|
||||
"int" integer NOT NULL,
|
||||
"int8" smallint CHECK("int8" >= -127 AND "int8" <= 128) NOT NULL,
|
||||
"int16" smallint NOT NULL,
|
||||
"int32" integer NOT NULL,
|
||||
"int64" bigint NOT NULL,
|
||||
"uint" bigint CHECK("uint" >= 0) NOT NULL,
|
||||
"uint8" smallint CHECK("uint8" >= 0 AND "uint8" <= 255) NOT NULL,
|
||||
"uint16" integer CHECK("uint16" >= 0) NOT NULL,
|
||||
"uint32" bigint CHECK("uint32" >= 0) NOT NULL,
|
||||
"uint64" bigint CHECK("uint64" >= 0) NOT NULL,
|
||||
"float32" double precision NOT NULL,
|
||||
"float64" double precision NOT NULL,
|
||||
"decimal" numeric(8, 4)
|
||||
);
|
||||
CREATE TABLE "data_null" (
|
||||
"id" serial NOT NULL PRIMARY KEY,
|
||||
"boolean" bool,
|
||||
"char" varchar(50),
|
||||
"text" text,
|
||||
"date" date,
|
||||
"date_time" timestamp with time zone,
|
||||
"byte" smallint CHECK("byte" >= 0 AND "byte" <= 255),
|
||||
"rune" integer,
|
||||
"int" integer,
|
||||
"int8" smallint CHECK("int8" >= -127 AND "int8" <= 128),
|
||||
"int16" smallint,
|
||||
"int32" integer,
|
||||
"int64" bigint,
|
||||
"uint" bigint CHECK("uint" >= 0),
|
||||
"uint8" smallint CHECK("uint8" >= 0 AND "uint8" <= 255),
|
||||
"uint16" integer CHECK("uint16" >= 0),
|
||||
"uint32" bigint CHECK("uint32" >= 0),
|
||||
"uint64" bigint CHECK("uint64" >= 0),
|
||||
"float32" double precision,
|
||||
"float64" double precision,
|
||||
"decimal" numeric(8, 4)
|
||||
);
|
||||
CREATE INDEX "user_profile_id" ON "user" ("profile_id");
|
||||
CREATE INDEX "post_user_id" ON "post" ("user_id");
|
||||
CREATE INDEX "comment_post_id" ON "comment" ("post_id");
|
||||
@ -269,6 +462,10 @@ CREATE INDEX "comment_parent_id" ON "comment" ("parent_id");
|
||||
`}
|
||||
|
||||
func init() {
|
||||
// err := os.Setenv("TZ", "+00:00")
|
||||
// fmt.Println(err)
|
||||
|
||||
RegisterModel(new(Data), new(DataNull))
|
||||
RegisterModel(new(User))
|
||||
RegisterModel(new(Profile))
|
||||
RegisterModel(new(Post))
|
||||
|
Reference in New Issue
Block a user