@@ -1082,6 +1082,40 @@ def hstore_encoder(obj):
1082
1082
DROP EXTENSION hstore
1083
1083
''' )
1084
1084
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
+
1085
1119
async def test_custom_codec_override_binary (self ):
1086
1120
"""Test overriding core codecs."""
1087
1121
import json
0 commit comments