diff --git a/acacore/database/base.py b/acacore/database/base.py index d4c7b4b..d95857a 100644 --- a/acacore/database/base.py +++ b/acacore/database/base.py @@ -57,10 +57,7 @@ def fetchalltuples(self) -> Generator[tuple, None, None]: Returns: Generator: A generator for the tuples in the cursor. """ - return ( - tuple(c.from_entry(v) for c, v in zip(self.columns, vs)) - for vs in self.cursor.fetchall() - ) + return (tuple(c.from_entry(v) for c, v in zip(self.columns, vs)) for vs in self.cursor.fetchall()) def fetchonetuple(self) -> Optional[tuple]: """ @@ -81,9 +78,7 @@ def fetchall(self) -> Generator[dict[str, Any], None, None]: def fetchall(self, model: Type[M]) -> Generator[M, None, None]: ... - def fetchall( - self, model: Optional[Type[M]] = None - ) -> Generator[Union[dict[str, Any], M], None, None]: + def fetchall(self, model: Optional[Type[M]] = None) -> Generator[Union[dict[str, Any], M], None, None]: """ Fetch all results from the cursor and return them as dicts, with the columns' names/aliases used as keys. @@ -104,8 +99,7 @@ def fetchall( ) return ( - {c.alias or c.name: c.from_entry(v) for c, v in zip(select_columns, vs)} - for vs in self.cursor.fetchall() + {c.alias or c.name: c.from_entry(v) for c, v in zip(select_columns, vs)} for vs in self.cursor.fetchall() ) @overload @@ -244,11 +238,7 @@ def create_statement(self, exist_ok: bool = True) -> str: elements.append( "(" + ", ".join(c.create_statement() for c in self.columns) - + ( - f", primary key ({', '.join(c.name for c in keys)})" - if (keys := self.keys) - else "" - ) + + (f", primary key ({', '.join(c.name for c in keys)})" if (keys := self.keys) else "") + ")", ) @@ -294,9 +284,7 @@ def select( statement += f" WHERE {where}" if order_by: - order_statements = [ - f"{c.name if isinstance(c, Column) else c} {s}" for c, s in order_by - ] + order_statements = [f"{c.name if isinstance(c, Column) else c} {s}" for c, s in order_by] statement += f" ORDER BY {','.join(order_statements)}" if limit is not None: @@ -456,13 +444,11 @@ def create_statement(self, exist_ok: bool = True) -> str: elements.append("AS") select_names = [ - f"{c.name} as {c.alias}" if c.alias else c.name - for c in [SelectColumn.from_column(c) for c in self.columns] + f"{c.name} as {c.alias}" if c.alias else c.name for c in [SelectColumn.from_column(c) for c in self.columns] ] elements.append( - f"SELECT {','.join(select_names)} " - f"FROM {self.on.name if isinstance(self.on, Table) else self.on}", + f"SELECT {','.join(select_names)} " f"FROM {self.on.name if isinstance(self.on, Table) else self.on}", ) if self.where: @@ -472,10 +458,7 @@ def create_statement(self, exist_ok: bool = True) -> str: elements.append("GROUP BY") elements.append( ",".join( - [ - c.alias or c.name - for c in [SelectColumn.from_column(c) for c in self.group_by] - ], + [c.alias or c.name for c in [SelectColumn.from_column(c) for c in self.group_by]], ), ) diff --git a/acacore/database/column.py b/acacore/database/column.py index 762aac0..acc06dd 100644 --- a/acacore/database/column.py +++ b/acacore/database/column.py @@ -56,9 +56,7 @@ def _schema_to_column(name: str, schema: dict) -> "Column": else: raise TypeError(f"Cannot recognize type from schema {schema!r}") elif schema_any_of: - if (schema_any_of[-1].get("type", None) != "null" and len(schema_any_of) > 1) or len( - schema_any_of - ) > 2: + if (schema_any_of[-1].get("type", None) != "null" and len(schema_any_of) > 1) or len(schema_any_of) > 2: raise TypeError(f"Cannot recognize type from schema {schema!r}") return _schema_to_column(name, {**schema_any_of[0], **schema}) else: