94f7ba8b by slene

orm add uint uint32 uint64 auto increment support

1 parent 7d7c9825
...@@ -102,9 +102,10 @@ func getDbCreateSql(al *alias) (sqls []string) { ...@@ -102,9 +102,10 @@ func getDbCreateSql(al *alias) (sqls []string) {
102 } 102 }
103 103
104 if fi.auto { 104 if fi.auto {
105 if al.Driver == DR_Postgres { 105 switch al.Driver {
106 case DR_Sqlite, DR_Postgres:
106 column += T["auto"] 107 column += T["auto"]
107 } else { 108 default:
108 column += col + " " + T["auto"] 109 column += col + " " + T["auto"]
109 } 110 }
110 } else if fi.pk { 111 } else if fi.pk {
......
...@@ -20,7 +20,7 @@ var sqliteOperators = map[string]string{ ...@@ -20,7 +20,7 @@ var sqliteOperators = map[string]string{
20 } 20 }
21 21
22 var sqliteTypes = map[string]string{ 22 var sqliteTypes = map[string]string{
23 "auto": "NOT NULL PRIMARY KEY AUTOINCREMENT", 23 "auto": "integer NOT NULL PRIMARY KEY AUTOINCREMENT",
24 "pk": "NOT NULL PRIMARY KEY", 24 "pk": "NOT NULL PRIMARY KEY",
25 "bool": "bool", 25 "bool": "bool",
26 "string": "varchar(%d)", 26 "string": "varchar(%d)",
......
...@@ -20,7 +20,6 @@ var ( ...@@ -20,7 +20,6 @@ var (
20 supportTag = map[string]int{ 20 supportTag = map[string]int{
21 "-": 1, 21 "-": 1,
22 "null": 1, 22 "null": 1,
23 "blank": 1,
24 "index": 1, 23 "index": 1,
25 "unique": 1, 24 "unique": 1,
26 "pk": 1, 25 "pk": 1,
......
...@@ -42,7 +42,7 @@ func registerModel(model interface{}, prefix string) { ...@@ -42,7 +42,7 @@ func registerModel(model interface{}, prefix string) {
42 if fi.name == "Id" { 42 if fi.name == "Id" {
43 if fi.sf.Tag.Get(defaultStructTagName) == "" { 43 if fi.sf.Tag.Get(defaultStructTagName) == "" {
44 switch fi.addrValue.Elem().Kind() { 44 switch fi.addrValue.Elem().Kind() {
45 case reflect.Int, reflect.Int64, reflect.Int32: 45 case reflect.Int, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint32, reflect.Uint64:
46 fi.auto = true 46 fi.auto = true
47 fi.pk = true 47 fi.pk = true
48 info.fields.pk = fi 48 info.fields.pk = fi
......
...@@ -93,7 +93,6 @@ type fieldInfo struct { ...@@ -93,7 +93,6 @@ type fieldInfo struct {
93 auto bool 93 auto bool
94 pk bool 94 pk bool
95 null bool 95 null bool
96 blank bool
97 index bool 96 index bool
98 unique bool 97 unique bool
99 initial StrTo 98 initial StrTo
...@@ -248,7 +247,6 @@ checkType: ...@@ -248,7 +247,6 @@ checkType:
248 fi.fullName = mi.fullName + "." + sf.Name 247 fi.fullName = mi.fullName + "." + sf.Name
249 248
250 fi.null = attrs["null"] 249 fi.null = attrs["null"]
251 fi.blank = attrs["blank"]
252 fi.index = attrs["index"] 250 fi.index = attrs["index"]
253 fi.auto = attrs["auto"] 251 fi.auto = attrs["auto"]
254 fi.pk = attrs["pk"] 252 fi.pk = attrs["pk"]
...@@ -257,7 +255,6 @@ checkType: ...@@ -257,7 +255,6 @@ checkType:
257 switch fieldType { 255 switch fieldType {
258 case RelManyToMany, RelReverseMany, RelReverseOne: 256 case RelManyToMany, RelReverseMany, RelReverseOne:
259 fi.null = false 257 fi.null = false
260 fi.blank = false
261 fi.index = false 258 fi.index = false
262 fi.auto = false 259 fi.auto = false
263 fi.pk = false 260 fi.pk = false
...@@ -360,22 +357,20 @@ checkType: ...@@ -360,22 +357,20 @@ checkType:
360 if fi.auto { 357 if fi.auto {
361 358
362 switch addrField.Elem().Kind() { 359 switch addrField.Elem().Kind() {
363 case reflect.Int, reflect.Int32, reflect.Int64: 360 case reflect.Int, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint32, reflect.Uint64:
364 default: 361 default:
365 err = fmt.Errorf("auto primary key only support int, int32, int64, but found `%s`", addrField.Elem().Kind()) 362 err = fmt.Errorf("auto primary key only support int, int32, int64, uint, uint32, uint64 but found `%s`", addrField.Elem().Kind())
366 goto end 363 goto end
367 } 364 }
368 365
369 fi.pk = true 366 fi.pk = true
370 } 367 }
371 fi.null = false 368 fi.null = false
372 fi.blank = false
373 fi.index = false 369 fi.index = false
374 fi.unique = false 370 fi.unique = false
375 } 371 }
376 372
377 if fi.unique { 373 if fi.unique {
378 fi.blank = false
379 fi.index = false 374 fi.index = false
380 } 375 }
381 376
......
...@@ -58,6 +58,11 @@ type DataNull struct { ...@@ -58,6 +58,11 @@ type DataNull struct {
58 Decimal float64 `orm:"digits(8);decimals(4);null"` 58 Decimal float64 `orm:"digits(8);decimals(4);null"`
59 } 59 }
60 60
61 // only for mysql
62 type UserBig struct {
63 Id uint64
64 }
65
61 type User struct { 66 type User struct {
62 Id int 67 Id int
63 UserName string `orm:"size(30);unique"` 68 UserName string `orm:"size(30);unique"`
......
...@@ -196,6 +196,7 @@ func TestSyncDb(t *testing.T) { ...@@ -196,6 +196,7 @@ func TestSyncDb(t *testing.T) {
196 RegisterModel(new(Post)) 196 RegisterModel(new(Post))
197 RegisterModel(new(Tag)) 197 RegisterModel(new(Tag))
198 RegisterModel(new(Comment)) 198 RegisterModel(new(Comment))
199 RegisterModel(new(UserBig))
199 200
200 BootStrap() 201 BootStrap()
201 202
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!