8000 feat: support dml returning by harshachinta · Pull Request #335 · googleapis/python-spanner-sqlalchemy · GitHub
[go: up one dir, main page]

Skip to content

feat: support dml returning #335

10000
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 7 commits into from
Oct 31, 2024
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
43 changes: 43 additions & 0 deletions test/test_suite_13.py
Original file line number Diff line number Diff line change
Expand Up @@ -2065,6 +2065,49 @@ def test_create_engine_wo_database(self):
assert connection.connection.database is None


class ReturningTest(fixtures.TestBase):
def setUp(self):
self._engine = create_engine(get_db_url())
metadata = MetaData()

self._table = Table(
"returning_test",
metadata,
Column("id", Integer, primary_key=True),
Column("data", String(16), nullable=False),
)

metadata.create_all(self._engine)

def test_returning_for_insert_and_update(self):
random_id = random.randint(1, 1000)
with self._engine.begin() as connection:
stmt = (
self._table.insert()
.values(id=random_id, data="some % value")
.returning(self._table.c.id)
)
row = connection.execute(stmt).fetchall()
eq_(
row,
[(random_id,)],
)

with self._engine.begin() as connection:
update_text = "some + value"
stmt = (
self._table.update()
.values(data=update_text)
.where(self._table.c.id == random_id)
.returning(self._table.c.data)
)
row = connection.execute(stmt).fetchall()
eq_(
row,
[(update_text,)],
)


@pytest.mark.skipif(
bool(os.environ.get("SPANNER_EMULATOR_HOST")), reason="Skipped on emulator"
)
Expand Down
43 changes: 43 additions & 0 deletions test/test_suite_14.py
Original file line number Diff line number Diff line change
Expand Up @@ -2399,6 +2399,49 @@ def test_create_engine_wo_database(self):
assert connection.connection.database is None


class ReturningTest(fixtures.TestBase):
def setUp(self):
self._engine = create_engine(get_db_url())
metadata = MetaData()

10000 self._table = Table(
"returning_test",
metadata,
Column("id", Integer, primary_key=True),
Column("data", String(16), nullable=False),
)

metadata.create_all(self._engine)

def test_returning_for_insert_and_update(self):
random_id = random.randint(1, 1000)
with self._engine.begin() as connection:
stmt = (
self._table.insert()
.values(id=random_id, data="some % value")
.returning(self._table.c.id)
)
row = connection.execute(stmt).fetchall()
eq_(
row,
[(random_id,)],
)

with self._engine.begin() as connection:
update_text = "some + value"
stmt = (
self._table.update()
.values(data=update_text)
.where(self._table.c.id == random_id)
.returning(self._table.c.data)
)
row = connection.execute(stmt).fetchall()
eq_(
row,
[(update_text,)],
)


@pytest.mark.skipif(
bool(os.environ.get("SPANNER_EMULATOR_HOST")), reason="Skipped on emulator"
)
Expand Down
43 changes: 43 additions & 0 deletions test/test_suite_20.py
Original file line number Diff line number Diff line change
Expand Up @@ -3113,6 +3113,49 @@ def test_create_engine_wo_database(self):
assert connection.connection.database is None


class ReturningTest(fixtures.TestBase):
def setUp(self):
self._engine = create_engine(get_db_url())
metadata = MetaData()

self._table = Table(
"returning_test",
metadata,
Column("id", Integer, primary_key=True),
Column("data", String(16), nullable=False),
)

metadata.create_all(self._engine)

def test_returning_for_insert_and_update(self):
random_id = random.randint(1, 1000)
with self._engine.begin() as connection:
stmt = (
self._table.insert()
.values(id=random_id, data="some % value")
.returning(self._table.c.id)
)
row = connection.execute(stmt).fetchall()
eq_(
row,
[(random_id,)],
)

with self._engine.begin() as connection:
update_text = "some + value"
stmt = (
self._table.update()
.values(data=update_text)
.where(self._table.c.id == random_id)
.returning(self._table.c.data)
)
row = connection.execute(stmt).fetchall()
eq_(
row,
[(update_text,)],
)


@pytest.mark.skipif(
bool(os.environ.get("SPANNER_EMULATOR_HOST")), reason="Skipped on emulator"
)
Expand Down
Loading
0