File tree Expand file tree Collapse file tree 1 file changed +18
-11
lines changed
packages/postgres-database/src/simcore_postgres_database Expand file tree Collapse file tree 1 file changed +18
-11
lines changed Original file line number Diff line number Diff line change @@ -181,18 +181,25 @@ async def update(
181181 Raises:
182182 ProjectsNodesNodeNotFound: _description_
183183 """
184- update_stmt = (
185- projects_nodes .update ()
186- .values (** values )
187- .where (
188- (projects_nodes .c .project_uuid == f"{ self .project_uuid } " )
189- & (projects_nodes .c .node_id == f"{ node_id } " )
190- )
191- .returning (
192- * [c for c in projects_nodes .c if c is not projects_nodes .c .project_uuid ]
193- )
184+ # Build the insert statement
185+ stmt = pg_insert (projects_nodes ).values (
186+ project_uuid = self .project_uuid ,
187+ node_id = node_id ,
188+ ** values ,
189+ )
190+
191+ # Define the conflict target and update if there is a conflict
192+ stmt = stmt .on_conflict_do_update (
193+ index_elements = [
194+ "project_uuid" ,
195+ "node_id" ,
196+ ], # The columns that define the conflict
197+ set_ = values , # Columns to be updated if there's a conflict
198+ )
199+ stmt = stmt .returning (
200+ * [c for c in projects_nodes .c if c is not projects_nodes .c .project_uuid ]
194201 )
195- result = await connection .execute (update_stmt )
202+ result = await connection .execute (stmt )
196203 row = await result .first ()
197204 if not row :
198205 raise ProjectNodesNodeNotFoundError (
You can’t perform that action at this time.
0 commit comments