Skip to content

Commit

Permalink
Add filters for table descriptions endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
jcjc712 committed Sep 12, 2023
1 parent ea3a37f commit afca33e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
4 changes: 3 additions & 1 deletion dataherald/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ def update_table_description(
pass

@abstractmethod
def list_table_descriptions(self) -> list[TableSchemaDetail]:
def list_table_descriptions(
self, db_connection_id: str | None = None, table_name: str | None = None
) -> list[TableSchemaDetail]:
pass

@abstractmethod
Expand Down
8 changes: 6 additions & 2 deletions dataherald/api/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,13 @@ def update_table_description(
return scanner_repository.update(table)

@override
def list_table_descriptions(self) -> list[TableSchemaDetail]:
def list_table_descriptions(
self, db_connection_id: str | None = None, table_name: str | None = None
) -> list[TableSchemaDetail]:
scanner_repository = DBScannerRepository(self.storage)
return scanner_repository.find_all()
return scanner_repository.find_by(
{"db_connection_id": db_connection_id, "table_name": table_name}
)

@override
def add_golden_records(
Expand Down
10 changes: 10 additions & 0 deletions dataherald/db_scanner/repository/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,13 @@ def find_all(self) -> list[TableSchemaDetail]:
obj.id = str(row["_id"])
result.append(obj)
return result

def find_by(self, query: dict) -> list[TableSchemaDetail]:
query = {k: v for k, v in query.items() if v}
rows = self.storage.find(DB_COLLECTION, query)
result = []
for row in rows:
obj = TableSchemaDetail(**row)
obj.id = str(row["_id"])
result.append(obj)
return result
6 changes: 4 additions & 2 deletions dataherald/server/fastapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,11 @@ def update_table_description(
table_description_id, table_description_request
)

def list_table_descriptions(self) -> list[TableSchemaDetail]:
def list_table_descriptions(
self, db_connection_id: str | None = None, table_name: str | None = None
) -> list[TableSchemaDetail]:
"""List table descriptions"""
return self._api.list_table_descriptions()
return self._api.list_table_descriptions(db_connection_id, table_name)

def execute_query(self, query: Query) -> tuple[str, dict]:
"""Executes a query on the given db_connection_id"""
Expand Down

0 comments on commit afca33e

Please sign in to comment.