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
299043c82fc0
Commit
299043c82fc0
authored
4 years ago
by
Christophe de Vienne
Browse files
Options
Downloads
Patches
Plain Diff
SQLHelper: add SyncRelationStrings
parent
fe82db40aa33
No related branches found
No related tags found
No related merge requests found
Pipeline
#6599
passed
4 years ago
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
database/sql_helper.go
+27
-0
27 additions, 0 deletions
database/sql_helper.go
with
27 additions
and
0 deletions
database/sql_helper.go
+
27
−
0
View file @
299043c8
...
...
@@ -71,3 +71,30 @@
}
return
nil
}
// SyncRelationStrings ...
func
(
h
*
SQLHelper
)
SyncRelationStrings
(
table
string
,
colFrom
string
,
colTo
string
,
colFromValue
string
,
colToValues
[]
string
,
)
error
{
// Upsert ts les couples
q
:=
sq
.
Insert
(
table
)
.
Columns
(
colFrom
,
colTo
)
for
_
,
value
:=
range
colToValues
{
q
=
q
.
Values
(
colFromValue
,
value
)
}
q
=
q
.
Suffix
(
"ON CONFLICT DO NOTHING"
)
if
_
,
err
:=
h
.
Exec
(
q
);
err
!=
nil
{
return
err
}
filter
:=
sq
.
And
{
sq
.
Eq
{
colFrom
:
colFromValue
}}
for
_
,
value
:=
range
colToValues
{
filter
=
append
(
filter
,
sq
.
NotEq
{
colTo
:
value
})
}
// Delete les valeurs non voulues
if
_
,
err
:=
h
.
Exec
(
sq
.
Delete
(
table
)
.
Where
(
filter
));
err
!=
nil
{
return
err
}
return
nil
}
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