-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/0.1.15' into main
- Loading branch information
Showing
6 changed files
with
108 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .generate_subquery_for_missing_values import generate_subquery_for_missing_values | ||
from .select_from import SelectFrom | ||
from .qa_case import QaCase, QaCaseError | ||
from .sql_view_generator import SqlViewGenerator | ||
from .subquery import Subquery | ||
from .subquery_from_dict import subquery_from_dict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from dataclasses import dataclass, field | ||
|
||
from django.apps import apps as django_apps | ||
from django.db import OperationalError, connection | ||
|
||
from .subquery_from_dict import subquery_from_dict | ||
|
||
|
||
class QaCaseError(Exception): | ||
pass | ||
|
||
|
||
@dataclass(kw_only=True) | ||
class QaCase: | ||
label: str = None | ||
dbtable: str = None | ||
label_lower: str = None | ||
fld_name: str | None = None | ||
where: str | None = None | ||
list_tables: list[tuple[str, str, str]] | None = field(default_factory=list) | ||
|
||
def __post_init__(self): | ||
if self.fld_name is None and self.where is None: | ||
raise QaCaseError("Expected either 'fld_name' or 'where'. Got None for both.") | ||
elif self.fld_name is not None and self.where is not None: | ||
raise QaCaseError("Expected either 'fld_name' or 'where', not both.") | ||
|
||
@property | ||
def sql(self): | ||
return subquery_from_dict([self.__dict__]) | ||
|
||
@property | ||
def model_cls(self): | ||
return django_apps.get_model(self.label_lower) | ||
|
||
def fetchall(self): | ||
sql = subquery_from_dict([self.__dict__]) | ||
with connection.cursor() as cursor: | ||
try: | ||
cursor.execute(sql) | ||
except OperationalError as e: | ||
raise QaCaseError(f"{e}. See {self}.") | ||
return cursor.fetchall() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters