Skip to content

Commit

Permalink
refactor!: map BigInteger to new BigInt scalar (#101)
Browse files Browse the repository at this point in the history
* fix: map BigInteger to a new Int64 custom scalar

* docs: update readme

* docs: add RELEASE.md file

* fix: rename Int64 to BigInt

---------

Authored by: Ido Slonimsky <[email protected]>
  • Loading branch information
IdoKendo authored Dec 29, 2023
1 parent 539a747 commit b62fe80
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ Natively supports the following SQLAlchemy types:
```python
Integer: int,
Float: float,
BigInteger: int,
BigInteger: BigInt,
Numeric: Decimal,
DateTime: datetime,
Date: date,
Expand Down
3 changes: 3 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Release type: patch

This change implements a new custom scalar `BigInt` that is mapped to SQLAlchemy's `BigInteger`.
5 changes: 4 additions & 1 deletion src/strawberry_sqlalchemy_mapper/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
resolve_model_node,
resolve_model_nodes,
)
from strawberry_sqlalchemy_mapper.scalars import BigInt

if TYPE_CHECKING:
from sqlalchemy.sql.expression import ColumnElement
Expand Down Expand Up @@ -193,7 +194,7 @@ class StrawberrySQLAlchemyMapper(Generic[BaseModelType]):
] = {
Integer: int,
Float: float,
BigInteger: int,
BigInteger: BigInt,
Numeric: Decimal,
DateTime: datetime,
Date: date,
Expand Down Expand Up @@ -353,6 +354,8 @@ def _convert_column_to_strawberry_type(
if item_type is SkipTypeSentinel:
return item_type
type_annotation = List[item_type] # type: ignore
elif isinstance(column.type, BigInteger):
type_annotation = BigInt
else:
for (
sqlalchemy_type,
Expand Down
10 changes: 10 additions & 0 deletions src/strawberry_sqlalchemy_mapper/scalars.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from typing import Union

import strawberry

BigInt = strawberry.scalar(
Union[int, str], # type: ignore
serialize=lambda v: int(v),
parse_value=lambda v: str(v),
description="BigInt field",
)

0 comments on commit b62fe80

Please sign in to comment.