Skip to content

Python: Eliminate runtime package and use sqlalchemy #939

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 16, 2021

Conversation

robholt
Copy link
Contributor

@robholt robholt commented Mar 11, 2021

Based on comments on my initial python codegen PR I've put together some potential changes to the generated python code.

I've marked this as a draft PR because I've only made manual edits to the authors example. Once we have a more solid idea of what the generated python code should look like I'll make the changes to the actual codegen code.

A quick overview of the changes:

  • Use stdlib dataclasses instead of pydantic
  • Use sqlalchemy as the execution engine
  • Query functions are now inside of classes
  • Eliminated the positional param issue, now $1 is replaced with :p1 instead of just %s.

Notes:

  • Asyncio support in sqlalchemy requires the 1.4 release, which is currently in beta. Not really a long-term issue though, as it will eventually be out of beta. I've also confirmed the non-async code works fine with the latest stable 1.3.x release.
  • The : character is special to sqlalchemy. The codegen will need to replace : with \\: in queries. I don't think this will cause issues, but there's always the potential for edge-case issues with regex replaces on the queries.

Copy link
Collaborator

@kyleconroy kyleconroy left a comment

Choose a reason for hiding this comment

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

Really excited about this! Let me know if you have any questions about my comments.

@robholt robholt marked this pull request as ready for review March 15, 2021 21:22
Copy link
Collaborator

@kyleconroy kyleconroy left a comment

Choose a reason for hiding this comment

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

Not sure why the tests are failing. Looks like you need to rebase as well. I'll hold off merging anything until this is green and ready to be merged in.

Robert Holt added 3 commits March 16, 2021 09:36
The generated example code is edited just to demostrate potential
improvements to the python codegen.

The main changes are using sqlalchemy as the exection engine and using
stdlib dataclasses instead of pydantic. This also eliminates the runtime
package.
Generated python code now only depends on sqlalchemy. Query functions
are now inside classes as well.
@robholt robholt force-pushed the python-improvements branch from c84ac49 to 5f73dbd Compare March 16, 2021 13:36
@robholt
Copy link
Contributor Author

robholt commented Mar 16, 2021

Github actions was having issues yesterday, which caused the tests to fail. I've pushed the rebased commits which triggered a new test run.

@kyleconroy kyleconroy merged commit 7eed90d into sqlc-dev:master Mar 16, 2021
victoraugustolls pushed a commit to Streppel/sqlc that referenced this pull request May 6, 2021
* Manually edit python example code

The generated example code is edited just to demostrate potential
improvements to the python codegen.

The main changes are using sqlalchemy as the exection engine and using
stdlib dataclasses instead of pydantic. This also eliminates the runtime
package.

* Remove leftover debug code in python tests

* Python: implement new codegen

Generated python code now only depends on sqlalchemy. Query functions
are now inside classes as well.
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.

2 participants