Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
94f7ba8b
authored
2013-08-22 18:35:26 +0800
by
slene
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
orm add uint uint32 uint64 auto increment support
1 parent
7d7c9825
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
13 additions
and
12 deletions
orm/cmd_utils.go
orm/db_sqlite.go
orm/models.go
orm/models_boot.go
orm/models_info_f.go
orm/models_test.go
orm/orm_test.go
orm/cmd_utils.go
View file @
94f7ba8
...
...
@@ -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
{
...
...
orm/db_sqlite.go
View file @
94f7ba8
...
...
@@ -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)"
,
...
...
orm/models.go
View file @
94f7ba8
...
...
@@ -20,7 +20,6 @@ var (
supportTag
=
map
[
string
]
int
{
"-"
:
1
,
"null"
:
1
,
"blank"
:
1
,
"index"
:
1
,
"unique"
:
1
,
"pk"
:
1
,
...
...
orm/models_boot.go
View file @
94f7ba8
...
...
@@ -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
.
Int
64
,
reflect
.
Int32
:
case
reflect
.
Int
,
reflect
.
Int
32
,
reflect
.
Int64
,
reflect
.
Uint
,
reflect
.
Uint32
,
reflect
.
Uint64
:
fi
.
auto
=
true
fi
.
pk
=
true
info
.
fields
.
pk
=
fi
...
...
orm/models_info_f.go
View file @
94f7ba8
...
...
@@ -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
}
...
...
orm/models_test.go
View file @
94f7ba8
...
...
@@ -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"`
...
...
orm/orm_test.go
View file @
94f7ba8
...
...
@@ -196,6 +196,7 @@ func TestSyncDb(t *testing.T) {
RegisterModel
(
new
(
Post
))
RegisterModel
(
new
(
Tag
))
RegisterModel
(
new
(
Comment
))
RegisterModel
(
new
(
UserBig
))
BootStrap
()
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment