Skip to content

Commit b62fe80

Browse files
authored
refactor!: map BigInteger to new BigInt scalar (#101)
* 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]>
1 parent 539a747 commit b62fe80

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Natively supports the following SQLAlchemy types:
136136
```python
137137
Integer: int,
138138
Float: float,
139-
BigInteger: int,
139+
BigInteger: BigInt,
140140
Numeric: Decimal,
141141
DateTime: datetime,
142142
Date: date,

RELEASE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Release type: patch
2+
3+
This change implements a new custom scalar `BigInt` that is mapped to SQLAlchemy's `BigInteger`.

src/strawberry_sqlalchemy_mapper/mapper.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
resolve_model_node,
9494
resolve_model_nodes,
9595
)
96+
from strawberry_sqlalchemy_mapper.scalars import BigInt
9697

9798
if TYPE_CHECKING:
9899
from sqlalchemy.sql.expression import ColumnElement
@@ -193,7 +194,7 @@ class StrawberrySQLAlchemyMapper(Generic[BaseModelType]):
193194
] = {
194195
Integer: int,
195196
Float: float,
196-
BigInteger: int,
197+
BigInteger: BigInt,
197198
Numeric: Decimal,
198199
DateTime: datetime,
199200
Date: date,
@@ -353,6 +354,8 @@ def _convert_column_to_strawberry_type(
353354
if item_type is SkipTypeSentinel:
354355
return item_type
355356
type_annotation = List[item_type] # type: ignore
357+
elif isinstance(column.type, BigInteger):
358+
type_annotation = BigInt
356359
else:
357360
for (
358361
sqlalchemy_type,
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from typing import Union
2+
3+
import strawberry
4+
5+
BigInt = strawberry.scalar(
6+
Union[int, str], # type: ignore
7+
serialize=lambda v: int(v),
8+
parse_value=lambda v: str(v),
9+
description="BigInt field",
10+
)

0 commit comments

Comments
 (0)