Skip to content

Commit 1f4b80c

Browse files
authored
SQLAlchemy Readme fix (#36)
* . * Automated pre-commit update * .
1 parent 94dff5b commit 1f4b80c

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

examples/sqlalchemy_1.6_to_2.0/README.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
This example demonstrates how to use Codegen to automatically migrate SQLAlchemy 1.6 code to the new 2.0-style query interface. For a complete walkthrough, check out our [tutorial](https://docs.codegen.com/tutorials/sqlalchemy-1.6-to-2.0).
66

7-
## What This Example Does
7+
## How the Migration Script Works
88

99
The migration script handles four key transformations:
1010

@@ -18,6 +18,9 @@ The migration script handles four key transformations:
1818
select(User).where(User.name == 'john')
1919
).scalars().all()
2020
```
21+
- Replaces legacy `query()` syntax with modern `select()` statements
22+
- Updates filter conditions to use explicit comparison operators
23+
- Adds proper `execute()` and `scalars()` chain
2124

2225
2. **Update Session Execution**
2326
```python
@@ -29,6 +32,9 @@ The migration script handles four key transformations:
2932
users = session.execute(select(User)).scalars().all()
3033
first_user = session.execute(select(User)).scalars().first()
3134
```
35+
- Modernizes session query methods with `execute()` pattern
36+
- Adds proper result handling with `scalars()`
37+
- Updates common operations like `all()`, `first()`, `one()`
3238

3339
3. **Modernize ORM Relationships**
3440
```python
@@ -42,6 +48,9 @@ The migration script handles four key transformations:
4248
class Address(Base):
4349
user = relationship("User", back_populates="addresses")
4450
```
51+
- Replaces deprecated `backref` with explicit `back_populates`
52+
- Creates bidirectional relationship definitions
53+
- Adds `use_list` parameter for collection relationships
4554

4655
4. **Add Type Annotations**
4756
```python
@@ -59,15 +68,27 @@ The migration script handles four key transformations:
5968
name: Mapped[str] = mapped_column()
6069
addresses: Mapped[List["Address"]] = relationship()
6170
```
71+
- Introduces `Mapped[]` type wrappers for all columns
72+
- Converts `Column()` to `mapped_column()`
73+
- Handles nullable fields with `Optional[]` types
6274

63-
## Understanding the Code
75+
## Running the Migration
6476

65-
- `input_repo` - Sample SQLAlchemy 1.6 application to migrate
66-
- `output_repo` - Sample SQLAlchemy 2.0 application after migration
77+
```bash
78+
# Install Codegen
79+
pip install codegen
80+
81+
# Run the migration
82+
python run.py
83+
```
6784

6885
## Learn More
6986

7087
- [Full Tutorial](https://docs.codegen.com/tutorials/sqlalchemy-1.6-to-2.0)
7188
- [SQLAlchemy Documentation](https://docs.sqlalchemy.org/en/20/)
7289
- [What's New in SQLAlchemy 2.0](https://docs.sqlalchemy.org/en/20/changelog/migration_20.html)
7390
- [Codegen Documentation](https://docs.codegen.com)
91+
92+
## Contributing
93+
94+
Feel free to submit issues and enhancement requests!

examples/sqlalchemy_type_annotations/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ class Book(Base):
132132
```bash
133133
# Install Codegen
134134
pip install codegen
135+
135136
# Run the migration
136137
python run.py
137138
```

0 commit comments

Comments
 (0)