This repository was archived by the owner on Aug 19, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +23
-3
lines changed
Expand file tree Collapse file tree 3 files changed +23
-3
lines changed Original file line number Diff line number Diff line change 11import typing
22
3- import orjson
43import psycopg
54import psycopg .adapt
65import psycopg .types
2019 TransactionBackend ,
2120)
2221
22+ try :
23+ import orjson
24+
25+ def load (data ):
26+ return orjson .loads (data )
27+
28+ def dump (data ):
29+ return orjson .dumps (data )
30+ except ImportError :
31+ import json
32+
33+ def load (data ):
34+ return json .loads (data .decode ("utf-8" ))
35+
36+ def dump (data ):
37+ return json .dumps (data ).encode ("utf-8" )
38+
2339
2440class JsonLoader (psycopg .adapt .Loader ):
2541 def load (self , data ):
26- return orjson . loads (data )
42+ return load (data )
2743
2844
2945class JsonDumper (psycopg .adapt .Dumper ):
3046 def dump (self , data ):
31- return orjson . dumps (data )
47+ return dump (data )
3248
3349
3450class PsycopgBackend (DatabaseBackend ):
Original file line number Diff line number Diff line change 11-e .
22
3+ # Speedups
4+ orjson == 3.9.15
5+
36# Async database drivers
47asyncmy == 0.2.9
58aiomysql == 0.2.0
Original file line number Diff line number Diff line change @@ -58,6 +58,7 @@ def get_packages(package):
5858 "psycopg3" : ["psycopg" , "psycopg-pool" ],
5959 "sqlite" : ["aiosqlite" ],
6060 "aiosqlite" : ["aiosqlite" ],
61+ "orjson" : ["orjson" ],
6162 },
6263 classifiers = [
6364 "Development Status :: 3 - Alpha" ,
You can’t perform that action at this time.
0 commit comments