Skip to content

Commit a97b22a

Browse files
authored
Merge branch 'launchbadge:main' into feat/json-any
2 parents 977b381 + 648250d commit a97b22a

4 files changed

Lines changed: 70 additions & 10 deletions

File tree

.github/workflows/sqlx.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ jobs:
181181
- run: >
182182
cargo build
183183
--no-default-features
184-
--test ${{ matrix.linking }}-macros
184+
--test sqlite-macros
185185
--features any,macros,${{ matrix.linking }},_unstable-all-types,runtime-${{ matrix.runtime }}
186186
env:
187187
SQLX_OFFLINE: true
@@ -193,7 +193,7 @@ jobs:
193193
- run: >
194194
cargo test
195195
--no-default-features
196-
--test ${{ matrix.linking }}-macros
196+
--test sqlite-macros
197197
--features any,macros,${{ matrix.linking }},_unstable-all-types,runtime-${{ matrix.runtime }}
198198
env:
199199
DATABASE_URL: sqlite://tests/sqlite/sqlite.db

Cargo.toml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -392,12 +392,7 @@ required-features = ["sqlite"]
392392
[[test]]
393393
name = "sqlite-macros"
394394
path = "tests/sqlite/macros.rs"
395-
required-features = ["sqlite", "macros"]
396-
397-
[[test]]
398-
name = "sqlite-unbundled-macros"
399-
path = "tests/sqlite/macros.rs"
400-
required-features = ["sqlite-unbundled", "macros"]
395+
required-features = ["_sqlite", "macros"]
401396

402397
[[test]]
403398
name = "sqlite-derives"

sqlx-core/src/types/json.rs

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,59 @@ where
196196
}
197197
}
198198

199-
// We don't have to implement Encode for JsonRawValue because that's covered by the default
200-
// implementation for Encode
199+
impl<DB> Type<DB> for Box<JsonRawValue>
200+
where
201+
for<'a> Json<&'a Self>: Type<DB>,
202+
DB: Database,
203+
{
204+
fn type_info() -> DB::TypeInfo {
205+
<Json<&Self> as Type<DB>>::type_info()
206+
}
207+
208+
fn compatible(ty: &DB::TypeInfo) -> bool {
209+
<Json<&Self> as Type<DB>>::compatible(ty)
210+
}
211+
}
212+
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+
201252
impl<'r, DB> Decode<'r, DB> for &'r JsonRawValue
202253
where
203254
Json<Self>: Decode<'r, DB>,
@@ -207,3 +258,13 @@ where
207258
<Json<Self> as Decode<DB>>::decode(value).map(|item| item.0)
208259
}
209260
}
261+
262+
impl<'r, DB> Decode<'r, DB> for Box<JsonRawValue>
263+
where
264+
Json<Self>: Decode<'r, DB>,
265+
DB: Database,
266+
{
267+
fn decode(value: <DB as Database>::ValueRef<'r>) -> Result<Self, BoxDynError> {
268+
<Json<Self> as Decode<DB>>::decode(value).map(|item| item.0)
269+
}
270+
}

tests/postgres/types.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,9 @@ mod json {
468468
.await?;
469469

470470
let value: &JsonRawValue = row.try_get(0)?;
471+
assert_eq!(value.get(), "{\"hello\": \"world\"}");
471472

473+
let value: Box<JsonRawValue> = row.try_get(0)?;
472474
assert_eq!(value.get(), "{\"hello\": \"world\"}");
473475

474476
// prepared, binary API
@@ -477,7 +479,9 @@ mod json {
477479
.await?;
478480

479481
let value: &JsonRawValue = row.try_get(0)?;
482+
assert_eq!(value.get(), "{\"hello\": \"world\"}");
480483

484+
let value: Box<JsonRawValue> = row.try_get(0)?;
481485
assert_eq!(value.get(), "{\"hello\": \"world\"}");
482486

483487
Ok(())

0 commit comments

Comments
 (0)