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
99f1e6c8
Commit
99f1e6c8
authored
Apr 09, 2016
by
miraclesu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
orm: fix golint
parent
e95bef13
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
59 additions
and
53 deletions
+59
-53
cmd_utils.go
orm/cmd_utils.go
+2
-2
db.go
orm/db.go
+4
-4
models_fields.go
orm/models_fields.go
+25
-19
models_info_f.go
orm/models_info_f.go
+2
-2
models_test.go
orm/models_test.go
+12
-12
orm_test.go
orm/orm_test.go
+14
-14
No files found.
orm/cmd_utils.go
View file @
99f1e6c8
...
...
@@ -90,7 +90,7 @@ checkColumn:
}
else
{
col
=
fmt
.
Sprintf
(
s
,
fi
.
digits
,
fi
.
decimals
)
}
case
TypeJ
son
Field
:
case
TypeJ
SON
Field
:
if
al
.
Driver
!=
DRPostgres
{
fieldType
=
TypeCharField
goto
checkColumn
...
...
@@ -290,7 +290,7 @@ func getColumnDefault(fi *fieldInfo) string {
case
TypeBooleanField
:
t
=
" DEFAULT %s "
d
=
"FALSE"
case
TypeJ
son
Field
,
TypeJsonbField
:
case
TypeJ
SON
Field
,
TypeJsonbField
:
d
=
"{}"
}
...
...
orm/db.go
View file @
99f1e6c8
...
...
@@ -141,7 +141,7 @@ func (d *dbBase) collectFieldValue(mi *modelInfo, fi *fieldInfo, ind reflect.Val
}
else
{
value
=
field
.
Bool
()
}
case
TypeCharField
,
TypeTextField
,
TypeJ
son
Field
,
TypeJsonbField
:
case
TypeCharField
,
TypeTextField
,
TypeJ
SON
Field
,
TypeJsonbField
:
if
ns
,
ok
:=
field
.
Interface
()
.
(
sql
.
NullString
);
ok
{
value
=
nil
if
ns
.
Valid
{
...
...
@@ -247,7 +247,7 @@ func (d *dbBase) collectFieldValue(mi *modelInfo, fi *fieldInfo, ind reflect.Val
field
.
Set
(
reflect
.
ValueOf
(
tnow
.
In
(
DefaultTimeLoc
)))
}
}
case
TypeJ
son
Field
,
TypeJsonbField
:
case
TypeJ
SON
Field
,
TypeJsonbField
:
if
s
,
ok
:=
value
.
(
string
);
(
ok
&&
len
(
s
)
==
0
)
||
value
==
nil
{
if
fi
.
colDefault
&&
fi
.
initial
.
Exist
()
{
value
=
fi
.
initial
.
String
()
...
...
@@ -1101,7 +1101,7 @@ setValue:
}
value
=
b
}
case
fieldType
==
TypeCharField
||
fieldType
==
TypeTextField
||
fieldType
==
TypeJ
son
Field
||
fieldType
==
TypeJsonbField
:
case
fieldType
==
TypeCharField
||
fieldType
==
TypeTextField
||
fieldType
==
TypeJ
SON
Field
||
fieldType
==
TypeJsonbField
:
if
str
==
nil
{
value
=
ToStr
(
val
)
}
else
{
...
...
@@ -1247,7 +1247,7 @@ setValue:
field
.
SetBool
(
value
.
(
bool
))
}
}
case
fieldType
==
TypeCharField
||
fieldType
==
TypeTextField
||
fieldType
==
TypeJ
son
Field
||
fieldType
==
TypeJsonbField
:
case
fieldType
==
TypeCharField
||
fieldType
==
TypeTextField
||
fieldType
==
TypeJ
SON
Field
||
fieldType
==
TypeJsonbField
:
if
isNative
{
if
ns
,
ok
:=
field
.
Interface
()
.
(
sql
.
NullString
);
ok
{
if
value
==
nil
{
...
...
orm/models_fields.go
View file @
99f1e6c8
...
...
@@ -38,7 +38,7 @@ const (
TypePositiveBigIntegerField
TypeFloatField
TypeDecimalField
TypeJ
son
Field
TypeJ
SON
Field
TypeJsonbField
RelForeignKey
RelOneToOne
...
...
@@ -148,7 +148,7 @@ func (e *CharField) RawValue() interface{} {
// verify CharField implement Fielder
var
_
Fielder
=
new
(
CharField
)
// A time, represented in go by a time.Time instance.
//
TimeField
A time, represented in go by a time.Time instance.
// only time values like 10:00:00
// Has a few extra, optional attr tag:
//
...
...
@@ -163,22 +163,27 @@ var _ Fielder = new(CharField)
// eg: `orm:"auto_now"` or `orm:"auto_now_add"`
type
TimeField
time
.
Time
// Value return the time.Time
func
(
e
TimeField
)
Value
()
time
.
Time
{
return
time
.
Time
(
e
)
}
// Set set the TimeField's value
func
(
e
*
TimeField
)
Set
(
d
time
.
Time
)
{
*
e
=
TimeField
(
d
)
}
// String convert time to string
func
(
e
*
TimeField
)
String
()
string
{
return
e
.
Value
()
.
String
()
}
// FieldType return enum type Date
func
(
e
*
TimeField
)
FieldType
()
int
{
return
TypeDateField
}
// SetRaw convert the interface to time.Time. Allow string and time.Time
func
(
e
*
TimeField
)
SetRaw
(
value
interface
{})
error
{
switch
d
:=
value
.
(
type
)
{
case
time
.
Time
:
...
...
@@ -195,6 +200,7 @@ func (e *TimeField) SetRaw(value interface{}) error {
return
nil
}
// RawValue return time value
func
(
e
*
TimeField
)
RawValue
()
interface
{}
{
return
e
.
Value
()
}
...
...
@@ -684,47 +690,47 @@ func (e *TextField) RawValue() interface{} {
// verify TextField implement Fielder
var
_
Fielder
=
new
(
TextField
)
// J
son
Field postgres json field.
type
J
son
Field
string
// J
SON
Field postgres json field.
type
J
SON
Field
string
// Value return J
son
Field value
func
(
j
J
son
Field
)
Value
()
string
{
// Value return J
SON
Field value
func
(
j
J
SON
Field
)
Value
()
string
{
return
string
(
j
)
}
// Set the J
son
Field value
func
(
j
*
J
son
Field
)
Set
(
d
string
)
{
*
j
=
J
son
Field
(
d
)
// Set the J
SON
Field value
func
(
j
*
J
SON
Field
)
Set
(
d
string
)
{
*
j
=
J
SON
Field
(
d
)
}
// String convert J
son
Field to string
func
(
j
*
J
son
Field
)
String
()
string
{
// String convert J
SON
Field to string
func
(
j
*
J
SON
Field
)
String
()
string
{
return
j
.
Value
()
}
// FieldType return enum type
func
(
j
*
J
son
Field
)
FieldType
()
int
{
return
TypeJ
son
Field
func
(
j
*
J
SON
Field
)
FieldType
()
int
{
return
TypeJ
SON
Field
}
// SetRaw convert interface string to string
func
(
j
*
J
son
Field
)
SetRaw
(
value
interface
{})
error
{
func
(
j
*
J
SON
Field
)
SetRaw
(
value
interface
{})
error
{
switch
d
:=
value
.
(
type
)
{
case
string
:
j
.
Set
(
d
)
default
:
return
fmt
.
Errorf
(
"<J
son
Field.SetRaw> unknown value `%s`"
,
value
)
return
fmt
.
Errorf
(
"<J
SON
Field.SetRaw> unknown value `%s`"
,
value
)
}
return
nil
}
// RawValue return J
son
Field value
func
(
j
*
J
son
Field
)
RawValue
()
interface
{}
{
// RawValue return J
SON
Field value
func
(
j
*
J
SON
Field
)
RawValue
()
interface
{}
{
return
j
.
Value
()
}
// verify J
son
Field implement Fielder
var
_
Fielder
=
new
(
J
son
Field
)
// verify J
SON
Field implement Fielder
var
_
Fielder
=
new
(
J
SON
Field
)
// JsonbField postgres json field.
type
JsonbField
string
...
...
orm/models_info_f.go
View file @
99f1e6c8
...
...
@@ -244,7 +244,7 @@ checkType:
case
"text"
:
fieldType
=
TypeTextField
case
"json"
:
fieldType
=
TypeJ
son
Field
fieldType
=
TypeJ
SON
Field
case
"jsonb"
:
fieldType
=
TypeJsonbField
}
...
...
@@ -349,7 +349,7 @@ checkType:
switch
fieldType
{
case
TypeBooleanField
:
case
TypeCharField
,
TypeJ
son
Field
,
TypeJsonbField
:
case
TypeCharField
,
TypeJ
SON
Field
,
TypeJsonbField
:
if
size
!=
""
{
v
,
e
:=
StrTo
(
size
)
.
Int32
()
if
e
!=
nil
{
...
...
orm/models_test.go
View file @
99f1e6c8
...
...
@@ -78,41 +78,41 @@ func (e *SliceStringField) RawValue() interface{} {
var
_
Fielder
=
new
(
SliceStringField
)
// A json field.
type
JSONField
struct
{
type
JSONField
Test
struct
{
Name
string
Data
string
}
func
(
e
*
JSONField
)
String
()
string
{
func
(
e
*
JSONField
Test
)
String
()
string
{
data
,
_
:=
json
.
Marshal
(
e
)
return
string
(
data
)
}
func
(
e
*
JSONField
)
FieldType
()
int
{
func
(
e
*
JSONField
Test
)
FieldType
()
int
{
return
TypeTextField
}
func
(
e
*
JSONField
)
SetRaw
(
value
interface
{})
error
{
func
(
e
*
JSONField
Test
)
SetRaw
(
value
interface
{})
error
{
switch
d
:=
value
.
(
type
)
{
case
string
:
return
json
.
Unmarshal
([]
byte
(
d
),
e
)
default
:
return
fmt
.
Errorf
(
"<J
son
Field.SetRaw> unknown value `%v`"
,
value
)
return
fmt
.
Errorf
(
"<J
SON
Field.SetRaw> unknown value `%v`"
,
value
)
}
}
func
(
e
*
JSONField
)
RawValue
()
interface
{}
{
func
(
e
*
JSONField
Test
)
RawValue
()
interface
{}
{
return
e
.
String
()
}
var
_
Fielder
=
new
(
JSONField
)
var
_
Fielder
=
new
(
JSONField
Test
)
type
Data
struct
{
ID
int
`orm:"column(id)"`
Boolean
bool
Char
string
`orm:"size(50)"`
Text
string
`orm:"type(text)"`
J
son
string
`orm:"type(json);default({\"name\":\"json\"})"`
J
SON
string
`orm:"type(json);default({\"name\":\"json\"})"`
Jsonb
string
`orm:"type(jsonb)"`
Time
time
.
Time
`orm:"type(time)"`
Date
time
.
Time
`orm:"type(date)"`
...
...
@@ -139,7 +139,7 @@ type DataNull struct {
Boolean
bool
`orm:"null"`
Char
string
`orm:"null;size(50)"`
Text
string
`orm:"null;type(text)"`
J
son
string
`orm:"type(json);null"`
J
SON
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)"`
...
...
@@ -243,7 +243,7 @@ type User struct {
ShouldSkip
string
`orm:"-"`
Nums
int
Langs
SliceStringField
`orm:"size(100)"`
Extra
JSONField
`orm:"type(text)"`
Extra
JSONField
Test
`orm:"type(text)"`
unexport
bool
`orm:"-"`
unexportBool
bool
}
...
...
@@ -394,12 +394,12 @@ func NewInLineOneToOne() *InLineOneToOne {
}
type
IntegerPk
struct
{
I
d
int64
`orm:"pk"`
I
D
int64
`orm:"pk"`
Value
string
}
type
UintPk
struct
{
I
d
uint32
`orm:"pk"`
I
D
uint32
`orm:"pk"`
Name
string
}
...
...
orm/orm_test.go
View file @
99f1e6c8
...
...
@@ -241,7 +241,7 @@ var DataValues = map[string]interface{}{
"Boolean"
:
true
,
"Char"
:
"char"
,
"Text"
:
"text"
,
"J
son
"
:
`{"name":"json"}`
,
"J
SON
"
:
`{"name":"json"}`
,
"Jsonb"
:
`{"name": "jsonb"}`
,
"Time"
:
time
.
Now
(),
"Date"
:
time
.
Now
(),
...
...
@@ -268,7 +268,7 @@ func TestDataTypes(t *testing.T) {
ind
:=
reflect
.
Indirect
(
reflect
.
ValueOf
(
&
d
))
for
name
,
value
:=
range
DataValues
{
if
name
==
"J
son
"
{
if
name
==
"J
SON
"
{
continue
}
e
:=
ind
.
FieldByName
(
name
)
...
...
@@ -316,7 +316,7 @@ func TestNullDataTypes(t *testing.T) {
throwFail
(
t
,
AssertIs
(
id
,
1
))
data
:=
`{"ok":1,"data":{"arr":[1,2],"msg":"gopher"}}`
d
=
DataNull
{
ID
:
1
,
J
son
:
data
}
d
=
DataNull
{
ID
:
1
,
J
SON
:
data
}
num
,
err
:=
dORM
.
Update
(
&
d
)
throwFail
(
t
,
err
)
throwFail
(
t
,
AssertIs
(
num
,
1
))
...
...
@@ -325,7 +325,7 @@ func TestNullDataTypes(t *testing.T) {
err
=
dORM
.
Read
(
&
d
)
throwFail
(
t
,
err
)
throwFail
(
t
,
AssertIs
(
d
.
J
son
,
data
))
throwFail
(
t
,
AssertIs
(
d
.
J
SON
,
data
))
throwFail
(
t
,
AssertIs
(
d
.
NullBool
.
Valid
,
false
))
throwFail
(
t
,
AssertIs
(
d
.
NullString
.
Valid
,
false
))
...
...
@@ -2027,9 +2027,9 @@ func TestInLineOneToOne(t *testing.T) {
func
TestIntegerPk
(
t
*
testing
.
T
)
{
its
:=
[]
IntegerPk
{
{
I
d
:
math
.
MinInt64
,
Value
:
"-"
},
{
I
d
:
0
,
Value
:
"0"
},
{
I
d
:
math
.
MaxInt64
,
Value
:
"+"
},
{
I
D
:
math
.
MinInt64
,
Value
:
"-"
},
{
I
D
:
0
,
Value
:
"0"
},
{
I
D
:
math
.
MaxInt64
,
Value
:
"+"
},
}
num
,
err
:=
dORM
.
InsertMulti
(
len
(
its
),
its
)
...
...
@@ -2037,7 +2037,7 @@ func TestIntegerPk(t *testing.T) {
throwFail
(
t
,
AssertIs
(
num
,
len
(
its
)))
for
_
,
intPk
:=
range
its
{
out
:=
IntegerPk
{
I
d
:
intPk
.
Id
}
out
:=
IntegerPk
{
I
D
:
intPk
.
ID
}
err
=
dORM
.
Read
(
&
out
)
throwFail
(
t
,
err
)
throwFail
(
t
,
AssertIs
(
out
.
Value
,
intPk
.
Value
))
...
...
@@ -2085,21 +2085,21 @@ func TestInsertAuto(t *testing.T) {
func
TestUintPk
(
t
*
testing
.
T
)
{
name
:=
"go"
u
:=
&
UintPk
{
I
d
:
8
,
I
D
:
8
,
Name
:
name
,
}
created
,
pk
,
err
:=
dORM
.
ReadOrCreate
(
u
,
"I
d
"
)
created
,
pk
,
err
:=
dORM
.
ReadOrCreate
(
u
,
"I
D
"
)
throwFail
(
t
,
err
)
throwFail
(
t
,
AssertIs
(
created
,
true
))
throwFail
(
t
,
AssertIs
(
u
.
Name
,
name
))
nu
:=
&
UintPk
{
I
d
:
8
}
created
,
pk
,
err
=
dORM
.
ReadOrCreate
(
nu
,
"I
d
"
)
nu
:=
&
UintPk
{
I
D
:
8
}
created
,
pk
,
err
=
dORM
.
ReadOrCreate
(
nu
,
"I
D
"
)
throwFail
(
t
,
err
)
throwFail
(
t
,
AssertIs
(
created
,
false
))
throwFail
(
t
,
AssertIs
(
nu
.
I
d
,
u
.
Id
))
throwFail
(
t
,
AssertIs
(
pk
,
u
.
I
d
))
throwFail
(
t
,
AssertIs
(
nu
.
I
D
,
u
.
ID
))
throwFail
(
t
,
AssertIs
(
pk
,
u
.
I
D
))
throwFail
(
t
,
AssertIs
(
nu
.
Name
,
name
))
dORM
.
Delete
(
u
)
...
...
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