Skip to content

Commit

Permalink
Merge pull request #318 Fixed list type as field result in sqlalchemy
Browse files Browse the repository at this point in the history
  • Loading branch information
rekby authored Jun 29, 2023
2 parents dc7182e + a434c51 commit 6f4d8f0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Add list type to converter from result to native type (fix problem with get list result in dbapi/sqlalchemy)

## 3.3.5 ##
* Fixed use positional argument instead of named in WriterAsyncIO.__del__
* Fixed release buffer while read topic by one messages
Expand Down
9 changes: 9 additions & 0 deletions tests/sqlalchemy/test_inspect.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from sqlalchemy import text

import ydb

import sqlalchemy as sa
Expand All @@ -18,3 +20,10 @@ def test_get_columns(driver_sync, sa_engine):
]

session.execute_scheme("DROP TABLE test")


def test_query_list(sa_engine):
with sa_engine.connect() as connection:
result = connection.execute(text("SELECT AsList(1, 2, 3, 4) as c"))
row = next(result)
assert row["c"] == [1, 2, 3, 4]
5 changes: 5 additions & 0 deletions ydb/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ def _optional_type_to_native(type_pb):
return types.OptionalType(type_to_native(type_pb.optional_type.item))


def _list_type_to_native(type_pb):
return types.ListType(type_to_native(type_pb.list_type.item))


def _primitive_type_to_native(type_pb):
return _primitive_type_by_id.get(type_pb.type_id)

Expand All @@ -240,6 +244,7 @@ def _null_type_factory(type_pb):
"type_id": _primitive_type_to_native,
"decimal_type": _decimal_type_to_native,
"null_type": _null_type_factory,
"list_type": _list_type_to_native,
}


Expand Down

0 comments on commit 6f4d8f0

Please sign in to comment.