This repository was archived by the owner on Aug 19, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +10
-10
lines changed
Expand file tree Collapse file tree 2 files changed +10
-10
lines changed Original file line number Diff line number Diff line change 11import getpass
2+ import json
23import logging
34import typing
45import uuid
56
67import aiopg
7- from sqlalchemy .dialects .postgresql import pypostgresql
8+ from aiopg .sa .engine import APGCompiler_psycopg2
9+ from sqlalchemy .dialects .postgresql .psycopg2 import PGDialect_psycopg2
810from sqlalchemy .engine .interfaces import Dialect , ExecutionContext
911from sqlalchemy .engine .result import ResultMetaData , RowProxy
1012from sqlalchemy .sql import ClauseElement
@@ -26,8 +28,10 @@ def __init__(
2628 self ._pool = None
2729
2830 def _get_dialect (self ) -> Dialect :
29- dialect = pypostgresql .dialect (paramstyle = "pyformat" )
30-
31+ dialect = PGDialect_psycopg2 (
32+ json_serializer = json .dumps , json_deserializer = lambda x : x
33+ )
34+ dialect .statement_compiler = APGCompiler_psycopg2
3135 dialect .implicit_returning = True
3236 dialect .supports_native_enum = True
3337 dialect .supports_smallserial = True # 9.2+
Original file line number Diff line number Diff line change 22import datetime
33import decimal
44import functools
5- import json
65import os
76
87import pytest
@@ -514,14 +513,10 @@ async def test_json_field(database_url):
514513 async with Database (database_url ) as database :
515514 async with database .transaction (force_rollback = True ):
516515 # execute()
517- query = session .insert ()
518516 data = {"text" : "hello" , "boolean" : True , "int" : 1 }
519517 values = {"data" : data }
520-
521- if database .url .scheme == "postgresql+aiopg" :
522- await database .execute (query , {"data" : json .dumps (data )})
523- else :
524- await database .execute (query , values )
518+ query = session .insert ()
519+ await database .execute (query , values )
525520
526521 # fetch_all()
527522 query = session .select ()
@@ -544,6 +539,7 @@ async def test_custom_field(database_url):
544539 # execute()
545540 query = custom_date .insert ()
546541 values = {"title" : "Hello, world" , "published" : today }
542+
547543 await database .execute (query , values )
548544
549545 # fetch_all()
You can’t perform that action at this time.
0 commit comments