1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-25 21:01:31 +00:00

orm add uint uint32 uint64 auto increment support

This commit is contained in:
slene 2013-08-22 18:35:26 +08:00
parent 7d7c9825e9
commit 94f7ba8bdf
7 changed files with 13 additions and 12 deletions

View File

@ -102,9 +102,10 @@ func getDbCreateSql(al *alias) (sqls []string) {
} }
if fi.auto { if fi.auto {
if al.Driver == DR_Postgres { switch al.Driver {
case DR_Sqlite, DR_Postgres:
column += T["auto"] column += T["auto"]
} else { default:
column += col + " " + T["auto"] column += col + " " + T["auto"]
} }
} else if fi.pk { } else if fi.pk {

View File

@ -20,7 +20,7 @@ var sqliteOperators = map[string]string{
} }
var sqliteTypes = map[string]string{ var sqliteTypes = map[string]string{
"auto": "NOT NULL PRIMARY KEY AUTOINCREMENT", "auto": "integer NOT NULL PRIMARY KEY AUTOINCREMENT",
"pk": "NOT NULL PRIMARY KEY", "pk": "NOT NULL PRIMARY KEY",
"bool": "bool", "bool": "bool",
"string": "varchar(%d)", "string": "varchar(%d)",

View File

@ -20,7 +20,6 @@ var (
supportTag = map[string]int{ supportTag = map[string]int{
"-": 1, "-": 1,
"null": 1, "null": 1,
"blank": 1,
"index": 1, "index": 1,
"unique": 1, "unique": 1,
"pk": 1, "pk": 1,

View File

@ -42,7 +42,7 @@ func registerModel(model interface{}, prefix string) {
if fi.name == "Id" { if fi.name == "Id" {
if fi.sf.Tag.Get(defaultStructTagName) == "" { if fi.sf.Tag.Get(defaultStructTagName) == "" {
switch fi.addrValue.Elem().Kind() { switch fi.addrValue.Elem().Kind() {
case reflect.Int, reflect.Int64, reflect.Int32: case reflect.Int, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint32, reflect.Uint64:
fi.auto = true fi.auto = true
fi.pk = true fi.pk = true
info.fields.pk = fi info.fields.pk = fi

View File

@ -93,7 +93,6 @@ type fieldInfo struct {
auto bool auto bool
pk bool pk bool
null bool null bool
blank bool
index bool index bool
unique bool unique bool
initial StrTo initial StrTo
@ -248,7 +247,6 @@ checkType:
fi.fullName = mi.fullName + "." + sf.Name fi.fullName = mi.fullName + "." + sf.Name
fi.null = attrs["null"] fi.null = attrs["null"]
fi.blank = attrs["blank"]
fi.index = attrs["index"] fi.index = attrs["index"]
fi.auto = attrs["auto"] fi.auto = attrs["auto"]
fi.pk = attrs["pk"] fi.pk = attrs["pk"]
@ -257,7 +255,6 @@ checkType:
switch fieldType { switch fieldType {
case RelManyToMany, RelReverseMany, RelReverseOne: case RelManyToMany, RelReverseMany, RelReverseOne:
fi.null = false fi.null = false
fi.blank = false
fi.index = false fi.index = false
fi.auto = false fi.auto = false
fi.pk = false fi.pk = false
@ -360,22 +357,20 @@ checkType:
if fi.auto { if fi.auto {
switch addrField.Elem().Kind() { switch addrField.Elem().Kind() {
case reflect.Int, reflect.Int32, reflect.Int64: case reflect.Int, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint32, reflect.Uint64:
default: default:
err = fmt.Errorf("auto primary key only support int, int32, int64, but found `%s`", addrField.Elem().Kind()) err = fmt.Errorf("auto primary key only support int, int32, int64, uint, uint32, uint64 but found `%s`", addrField.Elem().Kind())
goto end goto end
} }
fi.pk = true fi.pk = true
} }
fi.null = false fi.null = false
fi.blank = false
fi.index = false fi.index = false
fi.unique = false fi.unique = false
} }
if fi.unique { if fi.unique {
fi.blank = false
fi.index = false fi.index = false
} }

View File

@ -58,6 +58,11 @@ type DataNull struct {
Decimal float64 `orm:"digits(8);decimals(4);null"` Decimal float64 `orm:"digits(8);decimals(4);null"`
} }
// only for mysql
type UserBig struct {
Id uint64
}
type User struct { type User struct {
Id int Id int
UserName string `orm:"size(30);unique"` UserName string `orm:"size(30);unique"`

View File

@ -196,6 +196,7 @@ func TestSyncDb(t *testing.T) {
RegisterModel(new(Post)) RegisterModel(new(Post))
RegisterModel(new(Tag)) RegisterModel(new(Tag))
RegisterModel(new(Comment)) RegisterModel(new(Comment))
RegisterModel(new(UserBig))
BootStrap() BootStrap()