1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 13:50:54 +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 al.Driver == DR_Postgres {
switch al.Driver {
case DR_Sqlite, DR_Postgres:
column += T["auto"]
} else {
default:
column += col + " " + T["auto"]
}
} else if fi.pk {

View File

@ -20,7 +20,7 @@ var sqliteOperators = 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",
"bool": "bool",
"string": "varchar(%d)",

View File

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

View File

@ -42,7 +42,7 @@ func registerModel(model interface{}, prefix string) {
if fi.name == "Id" {
if fi.sf.Tag.Get(defaultStructTagName) == "" {
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.pk = true
info.fields.pk = fi

View File

@ -93,7 +93,6 @@ type fieldInfo struct {
auto bool
pk bool
null bool
blank bool
index bool
unique bool
initial StrTo
@ -248,7 +247,6 @@ checkType:
fi.fullName = mi.fullName + "." + sf.Name
fi.null = attrs["null"]
fi.blank = attrs["blank"]
fi.index = attrs["index"]
fi.auto = attrs["auto"]
fi.pk = attrs["pk"]
@ -257,7 +255,6 @@ checkType:
switch fieldType {
case RelManyToMany, RelReverseMany, RelReverseOne:
fi.null = false
fi.blank = false
fi.index = false
fi.auto = false
fi.pk = false
@ -360,22 +357,20 @@ checkType:
if fi.auto {
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:
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
}
fi.pk = true
}
fi.null = false
fi.blank = false
fi.index = false
fi.unique = false
}
if fi.unique {
fi.blank = false
fi.index = false
}

View File

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

View File

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