2
2
3
3
namespace Amp \Postgres \Internal ;
4
4
5
+ use Amp \Postgres \PostgresArray ;
5
6
use Amp \Postgres \PostgresByteA ;
6
7
use Amp \Postgres \PostgresExecutor ;
7
8
@@ -105,8 +106,9 @@ function encodeParam(PostgresExecutor $executor, mixed $value): string|int|float
105
106
return match (\gettype ($ value )) {
106
107
"NULL " , "integer " , "double " , "string " => $ value ,
107
108
"boolean " => $ value ? 't ' : 'f ' ,
108
- "array " => ' { ' . \implode ( ' , ' , \array_map ( fn ( $ i ) => encodeArrayItem ( $ executor , $ i ), $ value )) . ' } ' ,
109
+ "array " => encodeArray ( $ executor , $ value , ' , ' ) ,
109
110
"object " => match (true ) {
111
+ $ value instanceof PostgresArray => $ value ->encode ($ executor ),
110
112
$ value instanceof PostgresByteA => $ executor ->escapeByteA ($ value ->getData ()),
111
113
$ value instanceof \BackedEnum => $ value ->value ,
112
114
$ value instanceof \Stringable => (string ) $ value ,
@@ -122,6 +124,14 @@ function encodeParam(PostgresExecutor $executor, mixed $value): string|int|float
122
124
};
123
125
}
124
126
127
+ /**
128
+ * @internal
129
+ */
130
+ function encodeArray (PostgresExecutor $ executor , array $ array , string $ delimiter ): string
131
+ {
132
+ return '{ ' . \implode ($ delimiter , \array_map (fn ($ i ) => encodeArrayItem ($ executor , $ i ), $ array )) . '} ' ;
133
+ }
134
+
125
135
/**
126
136
* @internal
127
137
*
@@ -133,7 +143,10 @@ function encodeArrayItem(PostgresExecutor $executor, mixed $value): mixed
133
143
"NULL " => "NULL " ,
134
144
"string " => '" ' . \str_replace (['\\' , '" ' ], ['\\\\' , '\\" ' ], $ value ) . '" ' ,
135
145
"array " , "boolean " , "integer " , "double " => encodeParam ($ executor , $ value ),
136
- "object " => encodeArrayItem ($ executor , encodeParam ($ executor , $ value )),
146
+ "object " => match (true ) {
147
+ $ value instanceof PostgresArray => encodeParam ($ executor , $ value ),
148
+ default => encodeArrayItem ($ executor , encodeParam ($ executor , $ value )),
149
+ },
137
150
default => throw new \TypeError (\sprintf (
138
151
"Invalid value type '%s' in array " ,
139
152
\get_debug_type ($ value ),
0 commit comments