-
Notifications
You must be signed in to change notification settings - Fork 39
Add :copyfrom support #92
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
base: main
Are you sure you want to change the base?
Conversation
643c37c to
908c96f
Compare
908c96f to
2ff13ad
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements support for the :copyfrom command in sqlc-gen-python, enabling efficient bulk insert operations. The implementation leverages SQLAlchemy's executemany behavior by passing lists of parameter dictionaries to Connection.execute().
Key Changes:
- Added
:copyfromcommand support with automatic handling of both struct and non-struct parameters - Removed the previous error that blocked CopyFrom usage
- Added comprehensive test coverage and examples demonstrating both sync and async usage
Reviewed changes
Copilot reviewed 44 out of 45 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| internal/gen.go | Core implementation: adds BuildCopyFromBody, addCopyFromArgs, and buildStructToDictList methods; removes CopyFrom error; adds switch cases for :copyfrom in sync/async queriers |
| internal/imports.go | Adds import logic for typing.List and typing.Any types needed by copyfrom methods |
| internal/endtoend/testdata/copyfrom/* | New end-to-end test case with schema, queries, and expected generated code covering multiple copyfrom scenarios |
| examples/src/authors/query.sql | Adds example CreateAuthorsBatch copyfrom query |
| examples/src/authors/query.py | Generated code demonstrating copyfrom method with List[Any] parameter |
| examples/src/tests/test_authors.py | Test cases validating both sync and async copyfrom functionality |
| README.md | Documentation explaining copyfrom usage with examples for both List[Any] and typed struct parameters |
| internal/endtoend/testdata/*/sqlc.yaml | Updated sha256 hashes for new WASM binary version |
| internal/endtoend/testdata//python/.py | Updated generated file version comments from v1.28.0 to v1.29.0 |
| .gitignore | Adds .idea/ IDE directory to gitignore |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| body = append(body, assignNode(targetVar, poet.Node(&pyast.Call{ | ||
| Func: poet.Name("list"), | ||
| Args: []*pyast.Node{}, | ||
| }))) |
Copilot
AI
Nov 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using list() to create an empty list is less efficient than using a list literal []. In Python, [] is more idiomatic and has better performance since it doesn't require a function call. Consider updating the code generation to use [] instead of list().
Implements #63