Skip to content

Commit

Permalink
Add support for set types in Cassandra Model Mappers (#499)
Browse files Browse the repository at this point in the history
  • Loading branch information
JanusAsmussen authored Jan 9, 2025
1 parent 38e8bcc commit 4ee53ff
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def _map_to_column( # pylint: disable=R0911
:param type_to_map: Type to map.
:return: Cassandra column type.
"""
# pylint: disable=too-many-branches
if type_to_map is type(None):
raise TypeError("NoneType cannot be mapped to any existing table column types")
if type_to_map is bool:
Expand Down Expand Up @@ -157,6 +158,18 @@ def _map_to_column( # pylint: disable=R0911
columns.List,
self._map_to_column(list_element_type)[0],
)
if typing.get_origin(type_to_map) == set:
list_element_type = typing.get_args(type_to_map)[0]
if typing.get_origin(list_element_type) == dict:
return (
columns.Set,
self._map_to_column(list_element_type),
)
return (
columns.Set,
self._map_to_column(list_element_type)[0],
)

if typing.get_origin(type_to_map) == dict:
return (
columns.Map,
Expand Down

0 comments on commit 4ee53ff

Please sign in to comment.