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 +24
-3
lines changed Expand file tree Collapse file tree 3 files changed +24
-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+ 
31+ except  ImportError :
32+     import  json 
33+ 
34+     def  load (data ):
35+         return  json .loads (data .decode ("utf-8" ))
36+ 
37+     def  dump (data ):
38+         return  json .dumps (data ).encode ("utf-8" )
39+ 
2340
2441class  JsonLoader (psycopg .adapt .Loader ):
2542    def  load (self , data ):
26-         return  orjson . loads (data )
43+         return  load (data )
2744
2845
2946class  JsonDumper (psycopg .adapt .Dumper ):
3047    def  dump (self , data ):
31-         return  orjson . dumps (data )
48+         return  dump (data )
3249
3350
3451class  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