Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
b3096970
Commit
b3096970
authored
Nov 30, 2017
by
Back Yu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Proposal to #2952
parent
c3a81a23
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
22 additions
and
13 deletions
+22
-13
cmd_utils.go
orm/cmd_utils.go
+5
-3
db.go
orm/db.go
+3
-3
db_mysql.go
orm/db_mysql.go
+1
-0
db_oracle.go
orm/db_oracle.go
+1
-0
db_postgres.go
orm/db_postgres.go
+1
-0
db_sqlite.go
orm/db_sqlite.go
+1
-0
models_fields.go
orm/models_fields.go
+2
-1
models_info_f.go
orm/models_info_f.go
+4
-2
models_test.go
orm/models_test.go
+1
-1
models_utils.go
orm/models_utils.go
+3
-3
No files found.
orm/cmd_utils.go
View file @
b3096970
...
...
@@ -51,12 +51,14 @@ checkColumn:
switch
fieldType
{
case
TypeBooleanField
:
col
=
T
[
"bool"
]
case
TypeCharField
:
case
Type
Var
CharField
:
if
al
.
Driver
==
DRPostgres
&&
fi
.
toText
{
col
=
T
[
"string-text"
]
}
else
{
col
=
fmt
.
Sprintf
(
T
[
"string"
],
fieldSize
)
}
case
TypeCharField
:
col
=
fmt
.
Sprintf
(
T
[
"string-char"
],
fieldSize
)
case
TypeTextField
:
col
=
T
[
"string-text"
]
case
TypeTimeField
:
...
...
@@ -96,13 +98,13 @@ checkColumn:
}
case
TypeJSONField
:
if
al
.
Driver
!=
DRPostgres
{
fieldType
=
TypeCharField
fieldType
=
Type
Var
CharField
goto
checkColumn
}
col
=
T
[
"json"
]
case
TypeJsonbField
:
if
al
.
Driver
!=
DRPostgres
{
fieldType
=
TypeCharField
fieldType
=
Type
Var
CharField
goto
checkColumn
}
col
=
T
[
"jsonb"
]
...
...
orm/db.go
View file @
b3096970
...
...
@@ -142,7 +142,7 @@ func (d *dbBase) collectFieldValue(mi *modelInfo, fi *fieldInfo, ind reflect.Val
}
else
{
value
=
field
.
Bool
()
}
case
TypeCharField
,
TypeTextField
,
TypeJSONField
,
TypeJsonbField
:
case
Type
VarCharField
,
Type
CharField
,
TypeTextField
,
TypeJSONField
,
TypeJsonbField
:
if
ns
,
ok
:=
field
.
Interface
()
.
(
sql
.
NullString
);
ok
{
value
=
nil
if
ns
.
Valid
{
...
...
@@ -1240,7 +1240,7 @@ setValue:
}
value
=
b
}
case
fieldType
==
TypeCharField
||
fieldType
==
TypeTextField
||
fieldType
==
TypeJSONField
||
fieldType
==
TypeJsonbField
:
case
fieldType
==
Type
VarCharField
||
fieldType
==
Type
CharField
||
fieldType
==
TypeTextField
||
fieldType
==
TypeJSONField
||
fieldType
==
TypeJsonbField
:
if
str
==
nil
{
value
=
ToStr
(
val
)
}
else
{
...
...
@@ -1386,7 +1386,7 @@ setValue:
field
.
SetBool
(
value
.
(
bool
))
}
}
case
fieldType
==
TypeCharField
||
fieldType
==
TypeTextField
||
fieldType
==
TypeJSONField
||
fieldType
==
TypeJsonbField
:
case
fieldType
==
Type
VarCharField
||
fieldType
==
Type
CharField
||
fieldType
==
TypeTextField
||
fieldType
==
TypeJSONField
||
fieldType
==
TypeJsonbField
:
if
isNative
{
if
ns
,
ok
:=
field
.
Interface
()
.
(
sql
.
NullString
);
ok
{
if
value
==
nil
{
...
...
orm/db_mysql.go
View file @
b3096970
...
...
@@ -46,6 +46,7 @@ var mysqlTypes = map[string]string{
"pk"
:
"NOT NULL PRIMARY KEY"
,
"bool"
:
"bool"
,
"string"
:
"varchar(%d)"
,
"string-char"
:
"char(%d)"
,
"string-text"
:
"longtext"
,
"time.Time-date"
:
"date"
,
"time.Time"
:
"datetime"
,
...
...
orm/db_oracle.go
View file @
b3096970
...
...
@@ -34,6 +34,7 @@ var oracleTypes = map[string]string{
"pk"
:
"NOT NULL PRIMARY KEY"
,
"bool"
:
"bool"
,
"string"
:
"VARCHAR2(%d)"
,
"string-char"
:
"CHAR(%d)"
,
"string-text"
:
"VARCHAR2(%d)"
,
"time.Time-date"
:
"DATE"
,
"time.Time"
:
"TIMESTAMP"
,
...
...
orm/db_postgres.go
View file @
b3096970
...
...
@@ -43,6 +43,7 @@ var postgresTypes = map[string]string{
"pk"
:
"NOT NULL PRIMARY KEY"
,
"bool"
:
"bool"
,
"string"
:
"varchar(%d)"
,
"string-char"
:
"char(%d)"
,
"string-text"
:
"text"
,
"time.Time-date"
:
"date"
,
"time.Time"
:
"timestamp with time zone"
,
...
...
orm/db_sqlite.go
View file @
b3096970
...
...
@@ -43,6 +43,7 @@ var sqliteTypes = map[string]string{
"pk"
:
"NOT NULL PRIMARY KEY"
,
"bool"
:
"bool"
,
"string"
:
"varchar(%d)"
,
"string-char"
:
"character(%d)"
,
"string-text"
:
"text"
,
"time.Time-date"
:
"date"
,
"time.Time"
:
"datetime"
,
...
...
orm/models_fields.go
View file @
b3096970
...
...
@@ -23,6 +23,7 @@ import (
// Define the Type enum
const
(
TypeBooleanField
=
1
<<
iota
TypeVarCharField
TypeCharField
TypeTextField
TypeTimeField
...
...
@@ -126,7 +127,7 @@ func (e *CharField) String() string {
// FieldType return the enum type
func
(
e
*
CharField
)
FieldType
()
int
{
return
TypeCharField
return
Type
Var
CharField
}
// SetRaw set the interface to string
...
...
orm/models_info_f.go
View file @
b3096970
...
...
@@ -244,8 +244,10 @@ checkType:
if
err
!=
nil
{
goto
end
}
if
fieldType
==
TypeCharField
{
if
fieldType
==
Type
Var
CharField
{
switch
tags
[
"type"
]
{
case
"char"
:
fieldType
=
TypeCharField
case
"text"
:
fieldType
=
TypeTextField
case
"json"
:
...
...
@@ -357,7 +359,7 @@ checkType:
switch
fieldType
{
case
TypeBooleanField
:
case
TypeCharField
,
TypeJSONField
,
TypeJsonbField
:
case
Type
VarCharField
,
Type
CharField
,
TypeJSONField
,
TypeJsonbField
:
if
size
!=
""
{
v
,
e
:=
StrTo
(
size
)
.
Int32
()
if
e
!=
nil
{
...
...
orm/models_test.go
View file @
b3096970
...
...
@@ -49,7 +49,7 @@ func (e *SliceStringField) String() string {
}
func
(
e
*
SliceStringField
)
FieldType
()
int
{
return
TypeCharField
return
Type
Var
CharField
}
func
(
e
*
SliceStringField
)
SetRaw
(
value
interface
{})
error
{
...
...
orm/models_utils.go
View file @
b3096970
...
...
@@ -149,7 +149,7 @@ func getFieldType(val reflect.Value) (ft int, err error) {
case
reflect
.
TypeOf
(
new
(
bool
))
:
ft
=
TypeBooleanField
case
reflect
.
TypeOf
(
new
(
string
))
:
ft
=
TypeCharField
ft
=
Type
Var
CharField
case
reflect
.
TypeOf
(
new
(
time
.
Time
))
:
ft
=
TypeDateTimeField
default
:
...
...
@@ -176,7 +176,7 @@ func getFieldType(val reflect.Value) (ft int, err error) {
case
reflect
.
Bool
:
ft
=
TypeBooleanField
case
reflect
.
String
:
ft
=
TypeCharField
ft
=
Type
Var
CharField
default
:
if
elm
.
Interface
()
==
nil
{
panic
(
fmt
.
Errorf
(
"%s is nil pointer, may be miss setting tag"
,
val
))
...
...
@@ -189,7 +189,7 @@ func getFieldType(val reflect.Value) (ft int, err error) {
case
sql
.
NullBool
:
ft
=
TypeBooleanField
case
sql
.
NullString
:
ft
=
TypeCharField
ft
=
Type
Var
CharField
case
time
.
Time
:
ft
=
TypeDateTimeField
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment