Skip to content

Commit ee62a5a

Browse files
committed
Marshalling: Refactor
1 parent 20e735f commit ee62a5a

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/crate/client/http.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ def cratedb_json_encoder(obj):
9595
Encoder function for orjson.
9696
9797
https://github.com/ijl/orjson#default
98-
https://github.com/ijl/orjson#opt_passthrough_datetime
9998
"""
10099
if isinstance(obj, (Decimal, UUID)):
101100
return str(obj)
@@ -113,6 +112,14 @@ def cratedb_json_encoder(obj):
113112
return obj
114113

115114

115+
def json_dumps(obj):
116+
return orjson.dumps(
117+
obj,
118+
default=cratedb_json_encoder,
119+
option=orjson.OPT_SERIALIZE_NUMPY,
120+
)
121+
122+
116123
class Server:
117124
def __init__(self, server, **pool_kw):
118125
socket_options = _get_socket_opts(
@@ -340,11 +347,7 @@ def _create_sql_payload(stmt, args, bulk_args):
340347
data["args"] = args
341348
if bulk_args:
342349
data["bulk_args"] = bulk_args
343-
return orjson.dumps(
344-
data,
345-
default=cratedb_json_encoder,
346-
option=(orjson.OPT_PASSTHROUGH_DATETIME | orjson.OPT_SERIALIZE_NUMPY),
347-
)
350+
return json_dumps(data)
348351

349352

350353
def _get_socket_opts(

0 commit comments

Comments
 (0)