Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
meanspec-hwinfo-daemon
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MeanSpec (SCE338 2024-2 Group 1)
meanspec-hwinfo-daemon
Commits
3e29233d
Verified
Commit
3e29233d
authored
6 months ago
by
Eunhak Lee
Browse files
Options
Downloads
Patches
Plain Diff
chore: parts 테이블에 넣을 때 ON CONFLICT 동작 정의
parent
5e3bd7d4
No related branches found
No related tags found
1 merge request
!1
fix: 대몬이 여러 개 작동할 때 part 를 새로 생성하면서 생기는 conflict 해결
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
push_to_db.py
+2
-3
2 additions, 3 deletions
push_to_db.py
with
2 additions
and
3 deletions
push_to_db.py
+
2
−
3
View file @
3e29233d
...
@@ -61,10 +61,9 @@ def create_new_one(_dict, part_type, _cursor):
...
@@ -61,10 +61,9 @@ def create_new_one(_dict, part_type, _cursor):
columns
=
"
,
"
.
join
([
f
'"
{
key
}
"'
for
key
,
_
in
_obj
])
columns
=
"
,
"
.
join
([
f
'"
{
key
}
"'
for
key
,
_
in
_obj
])
values
=
[
value
for
_
,
value
in
_obj
]
values
=
[
value
for
_
,
value
in
_obj
]
sql
=
"""
WITH rows AS (INSERT INTO parts (name, type) VALUES (%s, %s) RETURNING id)
sql
=
"""
WITH rows AS (INSERT INTO parts (name, type) VALUES (%s, %s)
ON CONFLICT (name) DO UPDATE SET name = excluded.name
RETURNING id)
INSERT INTO part_info_{type} (part_id, {columns})
INSERT INTO part_info_{type} (part_id, {columns})
(SELECT rows.id, {value_entries} FROM rows)
(SELECT rows.id, {value_entries} FROM rows)
ON CONFLICT (name) DO UPDATE name = excluded.name
RETURNING part_id;
"""
.
format
(
type
=
_part_type_enum
,
columns
=
columns
,
value_entries
=
"
,
"
.
join
([
"
%s
"
]
*
len
(
values
)))
RETURNING part_id;
"""
.
format
(
type
=
_part_type_enum
,
columns
=
columns
,
value_entries
=
"
,
"
.
join
([
"
%s
"
]
*
len
(
values
)))
_cursor
.
execute
(
sql
,
(
name
,
_part_type_enum
,
*
values
))
_cursor
.
execute
(
sql
,
(
name
,
_part_type_enum
,
*
values
))
data
=
_cursor
.
fetchall
()
data
=
_cursor
.
fetchall
()
...
@@ -75,7 +74,7 @@ RETURNING part_id;""".format(type=_part_type_enum, columns=columns, value_entrie
...
@@ -75,7 +74,7 @@ RETURNING part_id;""".format(type=_part_type_enum, columns=columns, value_entrie
def
get_user_by_email
(
_cursor
,
_email
):
def
get_user_by_email
(
_cursor
,
_email
):
_cursor
.
execute
(
"
SELECT id FROM users WHERE email = %s;
"
,
(
_email
,))
_cursor
.
execute
(
"
SELECT id FROM users
d
WHERE email = %s;
"
,
(
_email
,))
data
=
_cursor
.
fetchall
()
data
=
_cursor
.
fetchall
()
if
data
:
if
data
:
...
...
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