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
1f68e5a7
Commit
1f68e5a7
authored
Jun 24, 2016
by
astaxie
Committed by
GitHub
Jun 24, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2006 from victorpopkov/develop
Add support for time.Time pointer in struct types
parents
ed474b51
415b9cf3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
1 deletion
+27
-1
db.go
orm/db.go
+10
-1
models_test.go
orm/models_test.go
+3
-0
models_utils.go
orm/models_utils.go
+2
-0
orm_test.go
orm/orm_test.go
+12
-0
No files found.
orm/db.go
View file @
1f68e5a7
...
@@ -243,6 +243,9 @@ func (d *dbBase) collectFieldValue(mi *modelInfo, fi *fieldInfo, ind reflect.Val
...
@@ -243,6 +243,9 @@ func (d *dbBase) collectFieldValue(mi *modelInfo, fi *fieldInfo, ind reflect.Val
if
fi
.
isFielder
{
if
fi
.
isFielder
{
f
:=
field
.
Addr
()
.
Interface
()
.
(
Fielder
)
f
:=
field
.
Addr
()
.
Interface
()
.
(
Fielder
)
f
.
SetRaw
(
tnow
.
In
(
DefaultTimeLoc
))
f
.
SetRaw
(
tnow
.
In
(
DefaultTimeLoc
))
}
else
if
field
.
Kind
()
==
reflect
.
Ptr
{
v
:=
tnow
.
In
(
DefaultTimeLoc
)
field
.
Set
(
reflect
.
ValueOf
(
&
v
))
}
else
{
}
else
{
field
.
Set
(
reflect
.
ValueOf
(
tnow
.
In
(
DefaultTimeLoc
)))
field
.
Set
(
reflect
.
ValueOf
(
tnow
.
In
(
DefaultTimeLoc
)))
}
}
...
@@ -1273,8 +1276,14 @@ setValue:
...
@@ -1273,8 +1276,14 @@ setValue:
if
isNative
{
if
isNative
{
if
value
==
nil
{
if
value
==
nil
{
value
=
time
.
Time
{}
value
=
time
.
Time
{}
}
else
if
field
.
Kind
()
==
reflect
.
Ptr
{
if
value
!=
nil
{
v
:=
value
.
(
time
.
Time
)
field
.
Set
(
reflect
.
ValueOf
(
&
v
))
}
}
else
{
field
.
Set
(
reflect
.
ValueOf
(
value
))
}
}
field
.
Set
(
reflect
.
ValueOf
(
value
))
}
}
case
fieldType
==
TypePositiveBitField
&&
field
.
Kind
()
==
reflect
.
Ptr
:
case
fieldType
==
TypePositiveBitField
&&
field
.
Kind
()
==
reflect
.
Ptr
:
if
value
!=
nil
{
if
value
!=
nil
{
...
...
orm/models_test.go
View file @
1f68e5a7
...
@@ -181,6 +181,9 @@ type DataNull struct {
...
@@ -181,6 +181,9 @@ type DataNull struct {
Float32Ptr
*
float32
`orm:"null"`
Float32Ptr
*
float32
`orm:"null"`
Float64Ptr
*
float64
`orm:"null"`
Float64Ptr
*
float64
`orm:"null"`
DecimalPtr
*
float64
`orm:"digits(8);decimals(4);null"`
DecimalPtr
*
float64
`orm:"digits(8);decimals(4);null"`
TimePtr
*
time
.
Time
`orm:"null;type(time)"`
DatePtr
*
time
.
Time
`orm:"null;type(date)"`
DateTimePtr
*
time
.
Time
`orm:"null"`
}
}
type
String
string
type
String
string
...
...
orm/models_utils.go
View file @
1f68e5a7
...
@@ -137,6 +137,8 @@ func getFieldType(val reflect.Value) (ft int, err error) {
...
@@ -137,6 +137,8 @@ func getFieldType(val reflect.Value) (ft int, err error) {
ft
=
TypeBooleanField
ft
=
TypeBooleanField
case
reflect
.
TypeOf
(
new
(
string
))
:
case
reflect
.
TypeOf
(
new
(
string
))
:
ft
=
TypeCharField
ft
=
TypeCharField
case
reflect
.
TypeOf
(
new
(
time
.
Time
))
:
ft
=
TypeDateTimeField
default
:
default
:
elm
:=
reflect
.
Indirect
(
val
)
elm
:=
reflect
.
Indirect
(
val
)
switch
elm
.
Kind
()
{
switch
elm
.
Kind
()
{
...
...
orm/orm_test.go
View file @
1f68e5a7
...
@@ -350,6 +350,9 @@ func TestNullDataTypes(t *testing.T) {
...
@@ -350,6 +350,9 @@ func TestNullDataTypes(t *testing.T) {
throwFail
(
t
,
AssertIs
(
d
.
Float32Ptr
,
nil
))
throwFail
(
t
,
AssertIs
(
d
.
Float32Ptr
,
nil
))
throwFail
(
t
,
AssertIs
(
d
.
Float64Ptr
,
nil
))
throwFail
(
t
,
AssertIs
(
d
.
Float64Ptr
,
nil
))
throwFail
(
t
,
AssertIs
(
d
.
DecimalPtr
,
nil
))
throwFail
(
t
,
AssertIs
(
d
.
DecimalPtr
,
nil
))
throwFail
(
t
,
AssertIs
(
d
.
TimePtr
,
nil
))
throwFail
(
t
,
AssertIs
(
d
.
DatePtr
,
nil
))
throwFail
(
t
,
AssertIs
(
d
.
DateTimePtr
,
nil
))
_
,
err
=
dORM
.
Raw
(
`INSERT INTO data_null (boolean) VALUES (?)`
,
nil
)
.
Exec
()
_
,
err
=
dORM
.
Raw
(
`INSERT INTO data_null (boolean) VALUES (?)`
,
nil
)
.
Exec
()
throwFail
(
t
,
err
)
throwFail
(
t
,
err
)
...
@@ -376,6 +379,9 @@ func TestNullDataTypes(t *testing.T) {
...
@@ -376,6 +379,9 @@ func TestNullDataTypes(t *testing.T) {
float32Ptr
:=
float32
(
42.0
)
float32Ptr
:=
float32
(
42.0
)
float64Ptr
:=
float64
(
42.0
)
float64Ptr
:=
float64
(
42.0
)
decimalPtr
:=
float64
(
42.0
)
decimalPtr
:=
float64
(
42.0
)
timePtr
:=
time
.
Now
()
datePtr
:=
time
.
Now
()
dateTimePtr
:=
time
.
Now
()
d
=
DataNull
{
d
=
DataNull
{
DateTime
:
time
.
Now
(),
DateTime
:
time
.
Now
(),
...
@@ -401,6 +407,9 @@ func TestNullDataTypes(t *testing.T) {
...
@@ -401,6 +407,9 @@ func TestNullDataTypes(t *testing.T) {
Float32Ptr
:
&
float32Ptr
,
Float32Ptr
:
&
float32Ptr
,
Float64Ptr
:
&
float64Ptr
,
Float64Ptr
:
&
float64Ptr
,
DecimalPtr
:
&
decimalPtr
,
DecimalPtr
:
&
decimalPtr
,
TimePtr
:
&
timePtr
,
DatePtr
:
&
datePtr
,
DateTimePtr
:
&
dateTimePtr
,
}
}
id
,
err
=
dORM
.
Insert
(
&
d
)
id
,
err
=
dORM
.
Insert
(
&
d
)
...
@@ -441,6 +450,9 @@ func TestNullDataTypes(t *testing.T) {
...
@@ -441,6 +450,9 @@ func TestNullDataTypes(t *testing.T) {
throwFail
(
t
,
AssertIs
(
*
d
.
Float32Ptr
,
float32Ptr
))
throwFail
(
t
,
AssertIs
(
*
d
.
Float32Ptr
,
float32Ptr
))
throwFail
(
t
,
AssertIs
(
*
d
.
Float64Ptr
,
float64Ptr
))
throwFail
(
t
,
AssertIs
(
*
d
.
Float64Ptr
,
float64Ptr
))
throwFail
(
t
,
AssertIs
(
*
d
.
DecimalPtr
,
decimalPtr
))
throwFail
(
t
,
AssertIs
(
*
d
.
DecimalPtr
,
decimalPtr
))
throwFail
(
t
,
AssertIs
((
*
d
.
TimePtr
)
.
Format
(
testTime
),
timePtr
.
Format
(
testTime
)))
throwFail
(
t
,
AssertIs
((
*
d
.
DatePtr
)
.
Format
(
testDate
),
datePtr
.
Format
(
testDate
)))
throwFail
(
t
,
AssertIs
((
*
d
.
DateTimePtr
)
.
Format
(
testDateTime
),
dateTimePtr
.
Format
(
testDateTime
)))
}
}
func
TestDataCustomTypes
(
t
*
testing
.
T
)
{
func
TestDataCustomTypes
(
t
*
testing
.
T
)
{
...
...
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