Skip to content

Commit b54b784

Browse files
committed
refactor join() method
1 parent 7024acf commit b54b784

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

simple_query_builder/querybuilder.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,15 @@ class QueryBuilder:
4646
]
4747
_JOIN_TYPES: list = [
4848
"INNER",
49+
"LEFT",
4950
"LEFT OUTER",
5051
"RIGHT OUTER",
5152
"FULL OUTER",
5253
"CROSS"
5354
]
5455
_SQLITE_JOIN_TYPES: list = [
5556
"INNER",
57+
"LEFT",
5658
"LEFT OUTER",
5759
"CROSS"
5860
]
@@ -178,7 +180,7 @@ def set_error(self, message: str = "") -> None:
178180
self._error = bool(message)
179181
self._error_message = message
180182
if self._print_errors and self._error:
181-
print(self._error_message)
183+
print("QueryBuilder error:", self._error_message)
182184

183185
def get_params(self) -> tuple:
184186
return self._params
@@ -611,9 +613,14 @@ def update(self, table: Union[str, dict], fields: Union[list, dict]):
611613

612614
def join(self, table: Union[str, dict] = "", on: Union[str, tuple, list] = (), join_type: str = "INNER"):
613615
join_type = join_type.upper()
614-
if join_type == "" or join_type not in self._SQLITE_JOIN_TYPES:
615-
self.set_error(f"Empty join_type or is not allowed in {inspect.stack()[0][3]} method")
616-
return self
616+
if self._db.get_driver() == 'sqlite':
617+
if join_type == "" or join_type not in self._SQLITE_JOIN_TYPES:
618+
self.set_error(f"Empty join_type or is not allowed in {inspect.stack()[0][3]} method. Try one of these {self._SQLITE_JOIN_TYPES}")
619+
return self
620+
else:
621+
if join_type == "" or join_type not in self._JOIN_TYPES:
622+
self.set_error(f"Empty join_type or is not allowed in {inspect.stack()[0][3]} method. Try one of these {self._JOIN_TYPES}")
623+
return self
617624

618625
if not table:
619626
self.set_error(f"Empty table in {inspect.stack()[0][3]} method")

0 commit comments

Comments
 (0)