Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
0127e08a
Commit
0127e08a
authored
Dec 10, 2023
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: data conflict handler
parent
d275713a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
14 additions
and
30 deletions
+14
-30
memo_organizer.go
store/db/postgres/memo_organizer.go
+4
-14
memo_relation.go
store/db/postgres/memo_relation.go
+1
-0
migration_history.go
store/db/postgres/migration_history.go
+3
-2
system_setting.go
store/db/postgres/system_setting.go
+4
-2
tag.go
store/db/postgres/tag.go
+2
-12
No files found.
store/db/postgres/memo_organizer.go
View file @
0127e08a
...
@@ -11,24 +11,14 @@ import (
...
@@ -11,24 +11,14 @@ import (
)
)
func
(
d
*
DB
)
UpsertMemoOrganizer
(
ctx
context
.
Context
,
upsert
*
store
.
MemoOrganizer
)
(
*
store
.
MemoOrganizer
,
error
)
{
func
(
d
*
DB
)
UpsertMemoOrganizer
(
ctx
context
.
Context
,
upsert
*
store
.
MemoOrganizer
)
(
*
store
.
MemoOrganizer
,
error
)
{
pinned
Value
:=
0
pinned
:=
0
if
upsert
.
Pinned
{
if
upsert
.
Pinned
{
pinned
Value
=
1
pinned
=
1
}
}
qb
:=
squirrel
.
Insert
(
"memo_organizer"
)
.
stmt
:=
"INSERT INTO memo_organizer (memo_id, user_id, pinned) VALUES ($1, $2, $3) ON CONFLICT (memo_id, user_id) DO UPDATE SET pinned = $4"
Columns
(
"memo_id"
,
"user_id"
,
"pinned"
)
.
if
_
,
err
:=
d
.
db
.
ExecContext
(
ctx
,
stmt
,
upsert
.
MemoID
,
upsert
.
UserID
,
pinned
,
pinned
);
err
!=
nil
{
Values
(
upsert
.
MemoID
,
upsert
.
UserID
,
pinnedValue
)
.
PlaceholderFormat
(
squirrel
.
Dollar
)
stmt
,
args
,
err
:=
qb
.
ToSql
()
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
if
_
,
err
=
d
.
db
.
ExecContext
(
ctx
,
stmt
,
args
...
);
err
!=
nil
{
return
nil
,
err
}
return
upsert
,
nil
return
upsert
,
nil
}
}
...
...
store/db/postgres/memo_relation.go
View file @
0127e08a
...
@@ -14,6 +14,7 @@ func (d *DB) UpsertMemoRelation(ctx context.Context, create *store.MemoRelation)
...
@@ -14,6 +14,7 @@ func (d *DB) UpsertMemoRelation(ctx context.Context, create *store.MemoRelation)
qb
:=
squirrel
.
Insert
(
"memo_relation"
)
.
qb
:=
squirrel
.
Insert
(
"memo_relation"
)
.
Columns
(
"memo_id"
,
"related_memo_id"
,
"type"
)
.
Columns
(
"memo_id"
,
"related_memo_id"
,
"type"
)
.
Values
(
create
.
MemoID
,
create
.
RelatedMemoID
,
create
.
Type
)
.
Values
(
create
.
MemoID
,
create
.
RelatedMemoID
,
create
.
Type
)
.
Suffix
(
"ON CONFLICT (version) DO NOTHING"
)
.
PlaceholderFormat
(
squirrel
.
Dollar
)
PlaceholderFormat
(
squirrel
.
Dollar
)
stmt
,
args
,
err
:=
qb
.
ToSql
()
stmt
,
args
,
err
:=
qb
.
ToSql
()
...
...
store/db/postgres/migration_history.go
View file @
0127e08a
...
@@ -44,9 +44,10 @@ func (d *DB) UpsertMigrationHistory(ctx context.Context, upsert *store.UpsertMig
...
@@ -44,9 +44,10 @@ func (d *DB) UpsertMigrationHistory(ctx context.Context, upsert *store.UpsertMig
qb
:=
squirrel
.
Insert
(
"migration_history"
)
.
qb
:=
squirrel
.
Insert
(
"migration_history"
)
.
Columns
(
"version"
)
.
Columns
(
"version"
)
.
Values
(
upsert
.
Version
)
.
Values
(
upsert
.
Version
)
.
Suffix
(
"ON CONFLICT (version) DO UPDATE SET version = ?"
,
upsert
.
Version
)
Suffix
(
"ON CONFLICT (version) DO NOTHING"
)
.
PlaceholderFormat
(
squirrel
.
Dollar
)
query
,
args
,
err
:=
qb
.
PlaceholderFormat
(
squirrel
.
Dollar
)
.
ToSql
()
query
,
args
,
err
:=
qb
.
ToSql
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
store/db/postgres/system_setting.go
View file @
0127e08a
...
@@ -11,9 +11,11 @@ import (
...
@@ -11,9 +11,11 @@ import (
func
(
d
*
DB
)
UpsertSystemSetting
(
ctx
context
.
Context
,
upsert
*
store
.
SystemSetting
)
(
*
store
.
SystemSetting
,
error
)
{
func
(
d
*
DB
)
UpsertSystemSetting
(
ctx
context
.
Context
,
upsert
*
store
.
SystemSetting
)
(
*
store
.
SystemSetting
,
error
)
{
qb
:=
squirrel
.
Insert
(
"system_setting"
)
.
qb
:=
squirrel
.
Insert
(
"system_setting"
)
.
Columns
(
"name"
,
"value"
,
"description"
)
.
Columns
(
"name"
,
"value"
,
"description"
)
.
Values
(
upsert
.
Name
,
upsert
.
Value
,
upsert
.
Description
)
Values
(
upsert
.
Name
,
upsert
.
Value
,
upsert
.
Description
)
.
Suffix
(
"ON CONFLICT (name) DO UPDATE SET value = EXCLUDED.value, description = EXCLUDED.description"
)
.
PlaceholderFormat
(
squirrel
.
Dollar
)
query
,
args
,
err
:=
qb
.
PlaceholderFormat
(
squirrel
.
Dollar
)
.
ToSql
()
query
,
args
,
err
:=
qb
.
ToSql
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
store/db/postgres/tag.go
View file @
0127e08a
...
@@ -11,20 +11,10 @@ import (
...
@@ -11,20 +11,10 @@ import (
)
)
func
(
d
*
DB
)
UpsertTag
(
ctx
context
.
Context
,
upsert
*
store
.
Tag
)
(
*
store
.
Tag
,
error
)
{
func
(
d
*
DB
)
UpsertTag
(
ctx
context
.
Context
,
upsert
*
store
.
Tag
)
(
*
store
.
Tag
,
error
)
{
builder
:=
squirrel
.
Insert
(
"tag"
)
.
stmt
:=
"INSERT INTO tag (name, creator_id) VALUES ($1, $2) ON CONFLICT (name, creator_id) DO UPDATE SET name = $3"
Columns
(
"name"
,
"creator_id"
)
.
if
_
,
err
:=
d
.
db
.
ExecContext
(
ctx
,
stmt
,
upsert
.
Name
,
upsert
.
CreatorID
,
upsert
.
Name
);
err
!=
nil
{
Values
(
upsert
.
Name
,
upsert
.
CreatorID
)
.
// on conflict is not necessary, as only the pair of name and creator_id is unique
PlaceholderFormat
(
squirrel
.
Dollar
)
query
,
args
,
err
:=
builder
.
ToSql
()
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
if
_
,
err
:=
d
.
db
.
ExecContext
(
ctx
,
query
,
args
...
);
err
!=
nil
{
return
nil
,
err
}
return
upsert
,
nil
return
upsert
,
nil
}
}
...
...
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