Skip to content

Commit 4e7f7b3

Browse files
authored
Merge pull request #96 from LuckySting/add-tupletype-mapping
Add TupleType mapping support for YDB
2 parents defb125 + 93c2718 commit 4e7f7b3

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

test/test_suite.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,19 @@ def test_from_as_table(self, connection):
577577

578578
eq_(connection.execute(sa.select(table)).fetchall(), [(1,), (2,), (3,)])
579579

580+
def test_tuple_list_type_bind_variable_text(self, connection):
581+
table = self.tables.container_types_test
582+
583+
connection.execute(sa.insert(table).values([{"id": 1}, {"id": 2}, {"id": 3}]))
584+
585+
stmt = select(table.c.id).where(
586+
sa.text("(id, id) IN :tuple_arr_var").bindparams(
587+
sa.bindparam("tuple_arr_var", type_=sa.ARRAY(sa.TupleType(sa.Integer, sa.Integer))),
588+
)
589+
)
590+
591+
eq_(connection.execute(stmt, {"tuple_arr_var": [(1, 1), (2, 2)]}).fetchall(), [(1,), (2,)])
592+
580593

581594
class ConcatTest(fixtures.TablesTest):
582595
@classmethod

ydb_sqlalchemy/sqlalchemy/compiler/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ def get_ydb_type(
228228
ydb_type = ydb.DecimalType(precision, scale)
229229
elif isinstance(type_, (types.ListType, sa.ARRAY)):
230230
ydb_type = ydb.ListType(self.get_ydb_type(type_.item_type, is_optional=False))
231+
elif isinstance(type_, sa.TupleType):
232+
ydb_type = ydb.TupleType()
233+
for item_type in type_.types:
234+
ydb_type.add_element(self.get_ydb_type(item_type, is_optional=False))
231235
elif isinstance(type_, types.StructType):
232236
ydb_type = ydb.StructType()
233237
for field, field_type in type_.fields_types.items():

0 commit comments

Comments
 (0)