Skip to content

Commit

Permalink
feat: turn one big query table into endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
vncsna committed Apr 26, 2024
1 parent b58a37c commit 4a6cf1a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 9 additions & 1 deletion bd_api/apps/api/v1/graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from graphene import UUID, Boolean, Float, List, ObjectType, String
from graphene_django import DjangoObjectType

from bd_api.apps.api.v1.models import TableNeighbor
from bd_api.apps.api.v1.models import Table, TableNeighbor
from bd_api.custom.graphql_base import PlainTextNode


Expand Down Expand Up @@ -45,6 +45,14 @@ class Query(ObjectType):
theme=String(),
share_theme=Boolean(),
)
get_table_one_big_table_query = String(
table_id=UUID(required=True),
columns=List(String),
)

def resolve_get_table_neighbor(root, info, table_id, **kwargs):
return TableNeighbor.objects.filter(table_a__pk=table_id).all()

def resolve_get_table_one_big_table_query(root, info, table_id, columns=None, **kwargs):
if table := Table.objects.filter(table__pk=table_id).first():
return table.gen_one_big_table_query(columns)
4 changes: 3 additions & 1 deletion bd_api/apps/api/v1/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ def gen_neighbors(self) -> list[dict]:
)
return all_neighbors

def gen_one_big_table_query(self):
def gen_one_big_table_query(self, columns: list[str] = None):
"""Get a denormalized sql query, similar to a one big table"""

def has_directory(column: Column):
Expand Down Expand Up @@ -1025,6 +1025,8 @@ def get_components():

column: Column
for column in self.columns.order_by("order").all():
if columns and column.name not in columns:
continue
if column.covered_by_dictionary:
sql_cte_table = f"dicionario_{column.name}"
sql_cte = f"""
Expand Down

0 comments on commit 4a6cf1a

Please sign in to comment.