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
9f3fbd52bc11
Commit
9f3fbd52bc11
authored
2 years ago
by
Christophe de Vienne
Browse files
Options
Downloads
Patches
Plain Diff
SQLHelper: add 'ForUpdate' versions of getter functions
parent
cbb304751ba8
No related branches found
No related tags found
No related merge requests found
Pipeline
#51859
failed
2 years ago
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
database/sql_helper.go
+26
-2
26 additions, 2 deletions
database/sql_helper.go
with
26 additions
and
2 deletions
database/sql_helper.go
+
26
−
2
View file @
9f3fbd52
...
@@ -31,8 +31,8 @@
...
@@ -31,8 +31,8 @@
return
h
.
sqle
.
GetContext
(
h
.
ctx
,
obj
,
sql
,
args
...
)
return
h
.
sqle
.
GetContext
(
h
.
ctx
,
obj
,
sql
,
args
...
)
}
}
// GetByPKey loads a mapped structure
// GetByPKey loads a mapped structure
by primary key
func
(
h
*
SQLHelper
)
GetByPKey
(
obj
Mapped
,
value
interface
{})
error
{
func
(
h
*
SQLHelper
)
GetByPKey
(
obj
Mapped
,
value
interface
{})
error
{
return
h
.
GetBy
(
obj
,
obj
.
PKeyColumn
(),
value
)
return
h
.
GetBy
(
obj
,
obj
.
PKeyColumn
(),
value
)
}
}
...
@@ -35,9 +35,15 @@
...
@@ -35,9 +35,15 @@
func
(
h
*
SQLHelper
)
GetByPKey
(
obj
Mapped
,
value
interface
{})
error
{
func
(
h
*
SQLHelper
)
GetByPKey
(
obj
Mapped
,
value
interface
{})
error
{
return
h
.
GetBy
(
obj
,
obj
.
PKeyColumn
(),
value
)
return
h
.
GetBy
(
obj
,
obj
.
PKeyColumn
(),
value
)
}
}
// GetBy ...
// GetByPKeyForUpdate loads a mapped structure by primary key and get a lock
// (see https://www.postgresql.org/docs/current/sql-select.html#SQL-FOR-UPDATE-SHARE)
func
(
h
*
SQLHelper
)
GetByPKeyForUpdate
(
obj
Mapped
,
value
interface
{})
error
{
return
h
.
GetByForUpdate
(
obj
,
obj
.
PKeyColumn
(),
value
)
}
// GetBy loads a mapped structure by a given column
func
(
h
*
SQLHelper
)
GetBy
(
obj
Mapped
,
column
string
,
value
interface
{})
error
{
func
(
h
*
SQLHelper
)
GetBy
(
obj
Mapped
,
column
string
,
value
interface
{})
error
{
return
h
.
GetWhere
(
obj
,
sq
.
Eq
{
column
:
value
})
return
h
.
GetWhere
(
obj
,
sq
.
Eq
{
column
:
value
})
}
}
...
@@ -40,7 +46,13 @@
...
@@ -40,7 +46,13 @@
func
(
h
*
SQLHelper
)
GetBy
(
obj
Mapped
,
column
string
,
value
interface
{})
error
{
func
(
h
*
SQLHelper
)
GetBy
(
obj
Mapped
,
column
string
,
value
interface
{})
error
{
return
h
.
GetWhere
(
obj
,
sq
.
Eq
{
column
:
value
})
return
h
.
GetWhere
(
obj
,
sq
.
Eq
{
column
:
value
})
}
}
// GetBy loads a mapped structure by a given column and get a lock
// (see https://www.postgresql.org/docs/current/sql-select.html#SQL-FOR-UPDATE-SHARE)
func
(
h
*
SQLHelper
)
GetByForUpdate
(
obj
Mapped
,
column
string
,
value
interface
{})
error
{
return
h
.
GetWhereForUpdate
(
obj
,
sq
.
Eq
{
column
:
value
})
}
// GetWhere loads a mapped structure
// GetWhere loads a mapped structure
func
(
h
*
SQLHelper
)
GetWhere
(
obj
Mapped
,
pred
interface
{},
args
...
interface
{})
error
{
func
(
h
*
SQLHelper
)
GetWhere
(
obj
Mapped
,
pred
interface
{},
args
...
interface
{})
error
{
query
:=
SQ
.
query
:=
SQ
.
...
@@ -51,6 +63,18 @@
...
@@ -51,6 +63,18 @@
return
h
.
Get
(
obj
,
query
)
return
h
.
Get
(
obj
,
query
)
}
}
// GetWhere loads a mapped structure and get a lock
// (see https://www.postgresql.org/docs/current/sql-select.html#SQL-FOR-UPDATE-SHARE)
func
(
h
*
SQLHelper
)
GetWhereForUpdate
(
obj
Mapped
,
pred
interface
{},
args
...
interface
{})
error
{
query
:=
SQ
.
Select
(
obj
.
Columns
(
true
)
...
)
.
From
(
obj
.
Table
())
.
Where
(
pred
,
args
...
)
.
Suffix
(
"FOR UPDATE"
)
return
h
.
Get
(
obj
,
query
)
}
// Select loads a structure list
// Select loads a structure list
func
(
h
*
SQLHelper
)
Select
(
obj
interface
{},
query
sq
.
Sqlizer
)
error
{
func
(
h
*
SQLHelper
)
Select
(
obj
interface
{},
query
sq
.
Sqlizer
)
error
{
return
SelectContext
(
h
.
ctx
,
h
.
sqle
,
obj
,
query
,
&
h
.
log
)
return
SelectContext
(
h
.
ctx
,
h
.
sqle
,
obj
,
query
,
&
h
.
log
)
...
...
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