Skip to content

Commit

Permalink
Changed NO_INPUT logic from string to class
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Schmidt committed Oct 19, 2023
1 parent 2357c00 commit e6be097
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/sql_mock/column_mocks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sql_mock.constants import NO_INPUT
from sql_mock.constants import NO_INPUT, NoInput


class ColumnMock:
Expand Down Expand Up @@ -29,7 +29,7 @@ def __init__(self, default=None, nullable=False) -> None:

def to_sql(self, column_name: str, value=NO_INPUT) -> str:
# Note: We compare against NO_INPUT instead of checking for None since None could be a valid input for nullable columns
val = value if value != NO_INPUT else self.default
val = value if not isinstance(value, NoInput) else self.default
# In case the val is None, we convert it to NULL
if val is None:
return f"cast(NULL AS {self.dtype}) AS {column_name}"
Expand Down
6 changes: 5 additions & 1 deletion src/sql_mock/constants.py
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
NO_INPUT = "NO INPUT PROVIDED"
class NoInput:
pass


NO_INPUT = NoInput()

0 comments on commit e6be097

Please sign in to comment.