Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed Jul 2, 2024
1 parent 0293bad commit 6872f4c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,34 @@ def list_services_with_history_stmt(
)
).label("history"),
).group_by(subquery.c.key)


def list_services_stmt2():
# Subquery to get the latest version for each key
subquery = sa.select(
services_meta_data.c.key,
services_meta_data.c.version,
services_meta_data.c.description,
func.row_number()
.over(
partition_by=services_meta_data.c.key,
order_by=sa.desc(_version(services_meta_data.c.version)),
)
.label("row_num"),
).alias("s")

return (
sa.select(
subquery.c.key,
subquery.c.description,
func.array_agg(services_meta_data.c.version).label("history"),
)
.select_from(
subquery.join(
services_meta_data, subquery.c.key == services_meta_data.c.key
)
)
.where(subquery.c.row_num == 1)
.group_by(subquery.c.key, subquery.c.description)
.order_by(subquery.c.key)
)
5 changes: 5 additions & 0 deletions services/catalog/tests/unit/with_dbs/test_db_repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from simcore_service_catalog.db.repositories._services_sql import (
AccessRightsClauses,
batch_get_services_stmt,
list_services_stmt2,
list_services_with_history_stmt,
total_count_stmt,
)
Expand Down Expand Up @@ -383,3 +384,7 @@ def test_services_sql_statements():
],
)
print(as_postgres_sql_query_str(stmt))

print(f"{list_services_stmt2.__name__:*^100}")
stmt = list_services_stmt2()
print(as_postgres_sql_query_str(stmt))

0 comments on commit 6872f4c

Please sign in to comment.