Skip to content

Commit 1fa0fa4

Browse files
style: apply ruff format to src/schemaforge/generators/typeorm_generator.py
1 parent ca34894 commit 1fa0fa4

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

src/schemaforge/generators/typeorm_generator.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Generator: SchemaForge IR → TypeORM entity schema."""
2+
23
from __future__ import annotations
34

45
from ..ir import Column, ColumnType, Schema
@@ -52,9 +53,7 @@ def generate(self, schema: Schema) -> str:
5253
imports = []
5354
if schema.tables:
5455
imports.append("Entity")
55-
has_pk = any(
56-
any(c.primary_key for c in t.columns) for t in schema.tables
57-
)
56+
has_pk = any(any(c.primary_key for c in t.columns) for t in schema.tables)
5857
if has_pk:
5958
imports.append("PrimaryGeneratedColumn")
6059
# Actually just always import Column since most tables have non-PK columns
@@ -70,12 +69,12 @@ def generate(self, schema: Schema) -> str:
7069
imports.append("Unique")
7170

7271
if len(imports) == 1 and imports[0] == "Entity":
73-
parts[0] = 'import { Entity, PrimaryGeneratedColumn, Column } from "typeorm";'
72+
parts[0] = (
73+
'import { Entity, PrimaryGeneratedColumn, Column } from "typeorm";'
74+
)
7475
else:
7576
parts[0] = (
76-
'import { '
77-
+ ", ".join(sorted(set(imports)))
78-
+ ' } from "typeorm";'
77+
"import { " + ", ".join(sorted(set(imports))) + ' } from "typeorm";'
7978
)
8079

8180
entities: list[str] = []
@@ -93,12 +92,10 @@ def _generate_entity(self, table) -> str:
9392
lines.append("@Entity()")
9493

9594
# Uniqueness constraints
96-
unique_cols = [
97-
c for c in table.columns if c.unique and not c.primary_key
98-
]
95+
unique_cols = [c for c in table.columns if c.unique and not c.primary_key]
9996
if unique_cols:
10097
col_names = ", ".join(f'"{c.name}"' for c in unique_cols)
101-
lines.append(f'@Unique({col_names})')
98+
lines.append(f"@Unique({col_names})")
10299

103100
# Class declaration
104101
lines.append(f"export class {table.name} {{")
@@ -124,7 +121,9 @@ def _column_def(self, col: Column) -> list[str]:
124121
options: dict[str, str] = {}
125122

126123
# Determine TypeORM type
127-
col_type = resolve_type(col, self._TYPE_MAP, fmt="typeorm", type_config=self._type_config)
124+
col_type = resolve_type(
125+
col, self._TYPE_MAP, fmt="typeorm", type_config=self._type_config
126+
)
128127

129128
# Primary key handling
130129
if col.primary_key:
@@ -157,7 +156,7 @@ def _column_def(self, col: Column) -> list[str]:
157156
options["default"] = str(col.default).lower()
158157
elif isinstance(col.default, str) and col.default.startswith("fn:"):
159158
fn_name = col.default[3:]
160-
options["default"] = f"() => \"{fn_name}\""
159+
options["default"] = f'() => "{fn_name}"'
161160
elif isinstance(col.default, str):
162161
options["default"] = f'"{col.default}"'
163162
elif isinstance(col.default, int | float):

0 commit comments

Comments
 (0)