Skip to content

Commit

Permalink
adding conversion of enum on postgresql data types
Browse files Browse the repository at this point in the history
  • Loading branch information
phenobarbital committed Dec 19, 2024
1 parent 930eea2 commit baa5628
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions asyncdb/drivers/pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""

import asyncio
from enum import Enum
import os
import ssl
import time
Expand Down Expand Up @@ -1178,6 +1179,8 @@ async def _insert_(self, _model: Model, **kwargs): # pylint: disable=W0613
value = getattr(value, name)
except AttributeError:
value = None
elif isinstance(value, Enum):
value = value.value
source.append(value)
cols.append(column)
n += 1
Expand Down Expand Up @@ -1299,6 +1302,8 @@ async def _update_(self, _model: Model, **kwargs): # pylint: disable=W0613
value = getattr(value, name)
except AttributeError:
value = None
elif isinstance(value, Enum):
value = value.value
cols.append("{} = {}".format(name, "${}".format(n))) # pylint: disable=C0209
source.append(value)
n += 1
Expand Down
3 changes: 3 additions & 0 deletions asyncdb/interfaces/model.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from enum import Enum
from typing import Any, List
from abc import ABC, abstractmethod
import uuid
Expand Down Expand Up @@ -122,6 +123,8 @@ def _get_value(self, field: Field, value: Any) -> Any:
new_val = None
elif callable(datatype) and value is None:
new_val = None
elif isinstance(value, Enum):
new_val = value.value
else:
new_val = value
return new_val
Expand Down
2 changes: 1 addition & 1 deletion asyncdb/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
__title__ = "asyncdb"
__description__ = "Library for Asynchronous data source connections \
Collection of asyncio drivers."
__version__ = "2.9.9"
__version__ = "2.9.10"
__author__ = "Jesus Lara"
__author_email__ = "[email protected]"
__license__ = "BSD"

0 comments on commit baa5628

Please sign in to comment.