Skip to content

Conversation

@vishalshenoy
Copy link
Contributor

No description provided.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ vishalshenoy
❌ codegen-bot


codegen-bot seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@vishalshenoy vishalshenoy merged commit 94dff5b into main Jan 29, 2025
1 of 2 checks passed
@vishalshenoy vishalshenoy deleted the vishal/fixsqlrun branch January 29, 2025 19:30
files_modified = 0
functions_modified = 0

print("\nStarting SQLAlchemy 1.6 to 2.0 migration...")
Copy link

@clee-codegen clee-codegen Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this type of logging can happen as part of the function wrapper in the CLI.

# Step 3: Convert Column Definitions to Type Annotations
for cls in file.classes:
for attr in cls.attributes:
if "Column(" in attr.source:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might want to make sure Column( is the beginning of the assignment

if "Column(" in attr.source:
original_attr = attr.source
new_attr = original_attr.replace("Column", "mapped_column")
type_hint = "Mapped" + original_attr.split("= Column")[1]
Copy link

@clee-codegen clee-codegen Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused by this here.

a = Column(Integer) should become
a: Mapped[int] = mapped_column()

I'm actually not sure what this new type hint would be based on this logic..

a: Mapped[(Integer)] ?

chain = chain.parent

original_code = chain.source
new_query = chain.source.replace("query(", "select(")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sqlalchemy 2.0 conventions are to use from sqlalchemy import select for everything right?

Wasn't 1.6 syntax more like

Model.query.filter()
session.query(Model)

and both of these should change to

session.scalars(select(Model).where(...))
or session.scalar(select(Modle).where(...))

and in cases where you're not querying the whole ORM object it would have to be

session.execute(select(Model.a, Model.b))

i believe filter_by is still valid too on the new select

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants