Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
go-orusapi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
orus-io
go-orusapi
Commits
f2bf45643d80
Commit
f2bf45643d80
authored
3 years ago
by
Florent Aide
Browse files
Options
Downloads
Patches
Plain Diff
added an UpdateColumns helper
parent
938b5b90d386
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#28252
passed
3 years ago
Stage: test
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
database/sql.go
+5
-2
5 additions, 2 deletions
database/sql.go
database/sql_helper.go
+9
-0
9 additions, 0 deletions
database/sql_helper.go
with
14 additions
and
2 deletions
database/sql.go
+
5
−
2
View file @
f2bf4564
...
...
@@ -123,6 +123,9 @@
// SQLUpdate generates a squirrel "update" statement
// for the given mapped instance (auto-selecting by its pkey)
func
SQLUpdate
(
m
Mapped
)
squirrel
.
UpdateBuilder
{
func
SQLUpdate
(
m
Mapped
,
columns
...
string
)
squirrel
.
UpdateBuilder
{
if
len
(
columns
)
==
0
{
columns
=
m
.
Columns
(
false
)
}
q
:=
squirrel
.
Update
(
m
.
Table
())
.
...
...
@@ -127,6 +130,6 @@
q
:=
squirrel
.
Update
(
m
.
Table
())
.
SetMap
(
ValuesMap
(
m
,
m
.
C
olumns
(
false
)
...
))
.
Where
(
SetMap
(
ValuesMap
(
m
,
c
olumns
...
))
.
Where
(
squirrel
.
Eq
{
m
.
PKeyColumn
()
:
m
.
Values
(
m
.
PKeyColumn
())})
return
q
}
...
...
This diff is collapsed.
Click to expand it.
database/sql_helper.go
+
9
−
0
View file @
f2bf4564
...
...
@@ -128,6 +128,15 @@
return
nil
}
// UpdateColumns update a mapped but only for the given columns
func
(
h
*
SQLHelper
)
UpdateColumns
(
instance
Mapped
,
columns
...
string
)
error
{
query
:=
SQLUpdate
(
instance
,
columns
...
)
if
_
,
err
:=
h
.
Exec
(
query
);
err
!=
nil
{
return
err
}
return
nil
}
// UpsertNoPKey upserts a Mapped into the db
func
(
h
*
SQLHelper
)
UpsertNoPKey
(
keyCols
[]
string
,
instances
...
Mapped
)
error
{
for
_
,
instance
:=
range
instances
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment