Skip to content

Commit

Permalink
database:base,column - format with black
Browse files Browse the repository at this point in the history
Change line length to 120
  • Loading branch information
MatteoCampinoti94 committed Oct 16, 2023
1 parent d68d983 commit f48e87b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 28 deletions.
33 changes: 8 additions & 25 deletions acacore/database/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
"""
Expand All @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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 "")
+ ")",
)

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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]],
),
)

Expand Down
4 changes: 1 addition & 3 deletions acacore/database/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit f48e87b

Please sign in to comment.