Skip to content

Commit aab820b

Browse files
committed
Add Encode impls for JsonRawValue.
1 parent 0bb965e commit aab820b

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

sqlx-core/src/types/json.rs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,45 @@ where
210210
}
211211
}
212212

213-
// We don't have to implement Encode for JsonRawValue because that's covered by the default
214-
// implementation for Encode
213+
impl<'q, DB> Encode<'q, DB> for JsonRawValue
214+
where
215+
for<'a> Json<&'a Self>: Encode<'q, DB>,
216+
DB: Database,
217+
{
218+
fn encode_by_ref(
219+
&self,
220+
buf: &mut <DB as Database>::ArgumentBuffer<'q>,
221+
) -> Result<IsNull, BoxDynError> {
222+
<Json<&Self> as Encode<'q, DB>>::encode(Json(self), buf)
223+
}
224+
}
225+
226+
impl<'q, DB> Encode<'q, DB> for &'q JsonRawValue
227+
where
228+
for<'a> Json<&'a Self>: Encode<'q, DB>,
229+
DB: Database,
230+
{
231+
fn encode_by_ref(
232+
&self,
233+
buf: &mut <DB as Database>::ArgumentBuffer<'q>,
234+
) -> Result<IsNull, BoxDynError> {
235+
<Json<&Self> as Encode<'q, DB>>::encode(Json(self), buf)
236+
}
237+
}
238+
239+
impl<'q, DB> Encode<'q, DB> for Box<JsonRawValue>
240+
where
241+
for<'a> Json<&'a Self>: Encode<'q, DB>,
242+
DB: Database,
243+
{
244+
fn encode_by_ref(
245+
&self,
246+
buf: &mut <DB as Database>::ArgumentBuffer<'q>,
247+
) -> Result<IsNull, BoxDynError> {
248+
<Json<&Self> as Encode<'q, DB>>::encode(Json(self), buf)
249+
}
250+
}
251+
215252
impl<'r, DB> Decode<'r, DB> for &'r JsonRawValue
216253
where
217254
Json<Self>: Decode<'r, DB>,

0 commit comments

Comments
 (0)