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
1786b16e
Commit
1786b16e
authored
Mar 23, 2016
by
miraclesu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
orm: support insert a specified value to auto field
parent
9f18813c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
13 deletions
+18
-13
db.go
orm/db.go
+18
-13
No files found.
orm/db.go
View file @
1786b16e
...
@@ -72,11 +72,11 @@ var _ dbBaser = new(dbBase)
...
@@ -72,11 +72,11 @@ var _ dbBaser = new(dbBase)
// get struct columns values as interface slice.
// get struct columns values as interface slice.
func
(
d
*
dbBase
)
collectValues
(
mi
*
modelInfo
,
ind
reflect
.
Value
,
cols
[]
string
,
skipAuto
bool
,
insert
bool
,
names
*
[]
string
,
tz
*
time
.
Location
)
(
values
[]
interface
{},
err
error
)
{
func
(
d
*
dbBase
)
collectValues
(
mi
*
modelInfo
,
ind
reflect
.
Value
,
cols
[]
string
,
skipAuto
bool
,
insert
bool
,
names
*
[]
string
,
tz
*
time
.
Location
)
(
values
[]
interface
{},
err
error
)
{
var
columns
[]
string
if
names
==
nil
{
ns
:=
make
([]
string
,
0
,
len
(
cols
))
if
names
!=
nil
{
names
=
&
ns
columns
=
*
names
}
}
values
=
make
([]
interface
{},
0
,
len
(
cols
))
for
_
,
column
:=
range
cols
{
for
_
,
column
:=
range
cols
{
var
fi
*
fieldInfo
var
fi
*
fieldInfo
...
@@ -93,15 +93,20 @@ func (d *dbBase) collectValues(mi *modelInfo, ind reflect.Value, cols []string,
...
@@ -93,15 +93,20 @@ func (d *dbBase) collectValues(mi *modelInfo, ind reflect.Value, cols []string,
return
nil
,
err
return
nil
,
err
}
}
if
names
!=
nil
{
// ignore empty value auto field
columns
=
append
(
columns
,
column
)
if
fi
.
auto
{
if
fi
.
fieldType
&
IsPositiveIntegerField
>
0
{
if
vu
,
ok
:=
value
.
(
uint64
);
!
ok
||
vu
==
0
{
continue
}
}
else
{
if
vu
,
ok
:=
value
.
(
int64
);
!
ok
||
vu
==
0
{
continue
}
}
}
}
values
=
append
(
values
,
value
)
*
names
,
values
=
append
(
*
names
,
column
),
append
(
values
,
value
)
}
if
names
!=
nil
{
*
names
=
columns
}
}
return
return
...
@@ -349,8 +354,8 @@ func (d *dbBase) Read(q dbQuerier, mi *modelInfo, ind reflect.Value, tz *time.Lo
...
@@ -349,8 +354,8 @@ func (d *dbBase) Read(q dbQuerier, mi *modelInfo, ind reflect.Value, tz *time.Lo
// execute insert sql dbQuerier with given struct reflect.Value.
// execute insert sql dbQuerier with given struct reflect.Value.
func
(
d
*
dbBase
)
Insert
(
q
dbQuerier
,
mi
*
modelInfo
,
ind
reflect
.
Value
,
tz
*
time
.
Location
)
(
int64
,
error
)
{
func
(
d
*
dbBase
)
Insert
(
q
dbQuerier
,
mi
*
modelInfo
,
ind
reflect
.
Value
,
tz
*
time
.
Location
)
(
int64
,
error
)
{
names
:=
make
([]
string
,
0
,
len
(
mi
.
fields
.
dbcols
)
-
1
)
names
:=
make
([]
string
,
0
,
len
(
mi
.
fields
.
dbcols
))
values
,
err
:=
d
.
collectValues
(
mi
,
ind
,
mi
.
fields
.
dbcols
,
tru
e
,
true
,
&
names
,
tz
)
values
,
err
:=
d
.
collectValues
(
mi
,
ind
,
mi
.
fields
.
dbcols
,
fals
e
,
true
,
&
names
,
tz
)
if
err
!=
nil
{
if
err
!=
nil
{
return
0
,
err
return
0
,
err
}
}
...
...
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