Skip to content

Conversation

@kellen-miller
Copy link

@kellen-miller kellen-miller commented Aug 23, 2025

Implements #63

@kellen-miller kellen-miller changed the title Add copyfrom Add :copyfrom support Aug 23, 2025
@devstein devstein requested review from Copilot, devstein and kyleconroy and removed request for Copilot and kyleconroy November 24, 2025 16:19
Copilot finished reviewing on behalf of devstein November 24, 2025 16:22
Copy link

Copilot AI left a 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 :copyfrom command 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.

Comment on lines +251 to +254
body = append(body, assignNode(targetVar, poet.Node(&pyast.Call{
Func: poet.Name("list"),
Args: []*pyast.Node{},
})))
Copy link

Copilot AI Nov 24, 2025

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().

Copilot uses AI. Check for mistakes.
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.

1 participant