Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions google/cloud/sqlalchemy_spanner/sqlalchemy_spanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,7 @@ class SpannerDialect(DefaultDialect):
insert_returning = True
update_returning = True
delete_returning = True
supports_multivalues_insert = True

ddl_compiler = SpannerDDLCompiler
preparer = SpannerIdentifierPreparer
Expand Down
29 changes: 29 additions & 0 deletions test/system/test_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,32 @@ class SchemaUser(Base):
select(SchemaUser).where(SchemaUser.name == "NewName")
).all()
eq_(0, len(users))

def test_multi_row_insert(self, connection):
"""Ensures we can perform multi-row inserts."""

class Base(DeclarativeBase):
pass

class User(Base):
__tablename__ = "users"
ID: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str] = mapped_column(String(20))

with connection.engine.begin() as conn:
inserted_rows = list(
conn.execute(
User.__table__.insert()
.values([{"name": "a"}, {"name": "b"}])
.returning(User.__table__.c.ID, User.__table__.c.name)
)
)

eq_(2, len(inserted_rows))
eq_({"a", "b"}, {row.name for row in inserted_rows})

with connection.engine.connect() as conn:
selected_rows = list(conn.execute(User.__table__.select()))

eq_(len(inserted_rows), len(selected_rows))
eq_(set(inserted_rows), set(selected_rows))