Skip to content

Commit

Permalink
Support BigInt columns (#54)
Browse files Browse the repository at this point in the history
Co-authored-by: Sergio Durban Belmonte <[email protected]>
  • Loading branch information
sdurban and sdurban authored Apr 3, 2020
1 parent 2ed6146 commit aa0a72f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions local_data_api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def from_value(cls, value: Any) -> Field:
return cls(stringValue=str(value))
elif type(value).__name__.endswith('PGobject'):
return cls(stringValue=str(value))
elif type(value).__name__.endswith('BigInteger'):
return cls(longValue=int(str(value)))
else:
raise Exception(f'unsupported type {type(value)}: {value} ')

Expand Down
9 changes: 9 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ def __str__(self) -> str:

assert Field.from_value(PGobject("{}")) == Field(stringValue="{}")

class BigInteger:
def __init__(self, val: int):
self._val: int = val

def __str__(self) -> int:
return self._val

assert Field.from_value(BigInteger("55")) == Field(longValue=55)

class Dummy:
pass

Expand Down

0 comments on commit aa0a72f

Please sign in to comment.