@@ -1082,6 +1082,40 @@ def hstore_encoder(obj):
10821082 DROP EXTENSION hstore
10831083 ''' )
10841084
1085+ async def test_custom_codec_on_domain (self ):
1086+ """Test encoding/decoding using a custom codec on a domain."""
1087+ await self .con .execute ('''
1088+ CREATE DOMAIN custom_codec_t AS int
1089+ ''' )
1090+
1091+ try :
1092+ await self .con .set_type_codec (
1093+ 'custom_codec_t' ,
1094+ encoder = lambda v : str (v ),
1095+ decoder = lambda v : int (v ))
1096+
1097+ v = await self .con .fetchval ('SELECT $1::custom_codec_t' , 10 )
1098+ self .assertEqual (v , 10 )
1099+ finally :
1100+ await self .con .execute ('DROP DOMAIN custom_codec_t' )
1101+
1102+ async def test_custom_codec_on_enum (self ):
1103+ """Test encoding/decoding using a custom codec on an enum."""
1104+ await self .con .execute ('''
1105+ CREATE TYPE custom_codec_t AS ENUM ('foo', 'bar', 'baz')
1106+ ''' )
1107+
1108+ try :
1109+ await self .con .set_type_codec (
1110+ 'custom_codec_t' ,
1111+ encoder = lambda v : str (v ).lstrip ('enum :' ),
1112+ decoder = lambda v : 'enum: ' + str (v ))
1113+
1114+ v = await self .con .fetchval ('SELECT $1::custom_codec_t' , 'foo' )
1115+ self .assertEqual (v , 'enum: foo' )
1116+ finally :
1117+ await self .con .execute ('DROP TYPE custom_codec_t' )
1118+
10851119 async def test_custom_codec_override_binary (self ):
10861120 """Test overriding core codecs."""
10871121 import json
0 commit comments