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
e95bef13
Commit
e95bef13
authored
Apr 08, 2016
by
miraclesu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
orm: add test case for json & jsonb type support
parent
657744ef
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
0 deletions
+17
-0
models_test.go
orm/models_test.go
+4
-0
orm_test.go
orm/orm_test.go
+13
-0
No files found.
orm/models_test.go
View file @
e95bef13
...
...
@@ -112,6 +112,8 @@ type Data struct {
Boolean
bool
Char
string
`orm:"size(50)"`
Text
string
`orm:"type(text)"`
Json
string
`orm:"type(json);default({\"name\":\"json\"})"`
Jsonb
string
`orm:"type(jsonb)"`
Time
time
.
Time
`orm:"type(time)"`
Date
time
.
Time
`orm:"type(date)"`
DateTime
time
.
Time
`orm:"column(datetime)"`
...
...
@@ -137,6 +139,8 @@ type DataNull struct {
Boolean
bool
`orm:"null"`
Char
string
`orm:"null;size(50)"`
Text
string
`orm:"null;type(text)"`
Json
string
`orm:"type(json);null"`
Jsonb
string
`orm:"type(jsonb);null"`
Time
time
.
Time
`orm:"null;type(time)"`
Date
time
.
Time
`orm:"null;type(date)"`
DateTime
time
.
Time
`orm:"null;column(datetime)"`
...
...
orm/orm_test.go
View file @
e95bef13
...
...
@@ -241,6 +241,8 @@ var DataValues = map[string]interface{}{
"Boolean"
:
true
,
"Char"
:
"char"
,
"Text"
:
"text"
,
"Json"
:
`{"name":"json"}`
,
"Jsonb"
:
`{"name": "jsonb"}`
,
"Time"
:
time
.
Now
(),
"Date"
:
time
.
Now
(),
"DateTime"
:
time
.
Now
(),
...
...
@@ -266,6 +268,9 @@ func TestDataTypes(t *testing.T) {
ind
:=
reflect
.
Indirect
(
reflect
.
ValueOf
(
&
d
))
for
name
,
value
:=
range
DataValues
{
if
name
==
"Json"
{
continue
}
e
:=
ind
.
FieldByName
(
name
)
e
.
Set
(
reflect
.
ValueOf
(
value
))
}
...
...
@@ -310,10 +315,18 @@ func TestNullDataTypes(t *testing.T) {
throwFail
(
t
,
err
)
throwFail
(
t
,
AssertIs
(
id
,
1
))
data
:=
`{"ok":1,"data":{"arr":[1,2],"msg":"gopher"}}`
d
=
DataNull
{
ID
:
1
,
Json
:
data
}
num
,
err
:=
dORM
.
Update
(
&
d
)
throwFail
(
t
,
err
)
throwFail
(
t
,
AssertIs
(
num
,
1
))
d
=
DataNull
{
ID
:
1
}
err
=
dORM
.
Read
(
&
d
)
throwFail
(
t
,
err
)
throwFail
(
t
,
AssertIs
(
d
.
Json
,
data
))
throwFail
(
t
,
AssertIs
(
d
.
NullBool
.
Valid
,
false
))
throwFail
(
t
,
AssertIs
(
d
.
NullString
.
Valid
,
false
))
throwFail
(
t
,
AssertIs
(
d
.
NullInt64
.
Valid
,
false
))
...
...
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