Skip to content

Commit 1e7f2bf

Browse files
committed
fix conflicts
1 parent 475d39a commit 1e7f2bf

File tree

5 files changed

+89
-124
lines changed

5 files changed

+89
-124
lines changed

sqlx-core/src/any/arguments.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ impl AnyArguments {
5454
i64: Type<A::Database> + Encode<'a, A::Database>,
5555
f32: Type<A::Database> + Encode<'a, A::Database>,
5656
f64: Type<A::Database> + Encode<'a, A::Database>,
57-
String: Type<A::Database> + Encode<'a, A::Database>,
58-
Vec<u8>: Type<A::Database> + Encode<'a, A::Database>,
57+
Arc<String>: Type<A::Database> + Encode<'a, A::Database>,
58+
Arc<str>: Type<A::Database> + Encode<'a, A::Database>,
59+
Arc<Vec<u8>>: Type<A::Database> + Encode<'a, A::Database>,
5960
A::Database: AnyJson,
6061
{
6162
let mut out = A::default();
@@ -82,8 +83,6 @@ impl AnyArguments {
8283
AnyValueKind::BigInt(i) => out.add(i),
8384
AnyValueKind::Real(r) => out.add(r),
8485
AnyValueKind::Double(d) => out.add(d),
85-
#[cfg(feature = "json")]
86-
AnyValueKind::Json(j) => A::Database::add_json(&mut out, j),
8786
AnyValueKind::Text(t) => out.add(t),
8887
AnyValueKind::TextSlice(t) => out.add(t),
8988
AnyValueKind::Blob(b) => out.add(b),

sqlx-core/src/any/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub trait AnyJson: crate::database::Database {
5959
value: Box<serde_json::value::RawValue>,
6060
) -> Result<(), crate::error::BoxDynError>
6161
where
62-
A: crate::arguments::Arguments<'a, Database = Self>;
62+
A: crate::arguments::Arguments<Database = Self>;
6363

6464
#[cfg(feature = "json")]
6565
fn decode_json(
@@ -79,12 +79,12 @@ where
7979
crate::types::Json<Box<serde_json::value::RawValue>>:
8080
Type<DB> + for<'a> crate::decode::Decode<'a, DB> + for<'a> crate::encode::Encode<'a, DB>,
8181
{
82-
fn add_json<'a, A>(
82+
fn add_json<A>(
8383
args: &mut A,
8484
value: Box<serde_json::value::RawValue>,
8585
) -> Result<(), crate::error::BoxDynError>
8686
where
87-
A: crate::arguments::Arguments<'a, Database = Self>,
87+
A: crate::arguments::Arguments<Database = Self>,
8888
{
8989
args.add(crate::types::Json(value))
9090
}

sqlx-core/src/any/types/json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl<T> Encode<'_, Any> for Json<T>
2424
where
2525
T: Serialize,
2626
{
27-
fn encode_by_ref(&self, buf: &mut AnyArgumentBuffer<'_>) -> Result<IsNull, BoxDynError> {
27+
fn encode_by_ref(&self, buf: &mut AnyArgumentBuffer) -> Result<IsNull, BoxDynError> {
2828
let json_string = self.encode_to_string()?;
2929
let raw_value = serde_json::value::RawValue::from_string(json_string)?;
3030
buf.0.push(AnyValueKind::Json(raw_value));

sqlx-core/src/any/value.rs

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ pub enum AnyValueKind {
1616
BigInt(i64),
1717
Real(f32),
1818
Double(f64),
19-
#[cfg(feature = "json")]
20-
#[cfg_attr(docsrs, doc(cfg(feature = "json")))]
21-
Json(Box<serde_json::value::RawValue>),
2219
Text(Arc<String>),
2320
TextSlice(Arc<str>),
2421
Blob(Arc<Vec<u8>>),
@@ -82,25 +79,7 @@ impl Value for AnyValue {
8279
type Database = Any;
8380

8481
fn as_ref(&self) -> <Self::Database as Database>::ValueRef<'_> {
85-
<<<<<<< HEAD
8682
AnyValueRef { kind: &self.kind }
87-
=======
88-
AnyValueRef {
89-
kind: match &self.kind {
90-
AnyValueKind::Null(k) => AnyValueKind::Null(*k),
91-
AnyValueKind::Bool(b) => AnyValueKind::Bool(*b),
92-
AnyValueKind::SmallInt(i) => AnyValueKind::SmallInt(*i),
93-
AnyValueKind::Integer(i) => AnyValueKind::Integer(*i),
94-
AnyValueKind::BigInt(i) => AnyValueKind::BigInt(*i),
95-
AnyValueKind::Real(r) => AnyValueKind::Real(*r),
96-
AnyValueKind::Double(d) => AnyValueKind::Double(*d),
97-
AnyValueKind::Text(t) => AnyValueKind::Text(Cow::Borrowed(t)),
98-
AnyValueKind::Blob(b) => AnyValueKind::Blob(Cow::Borrowed(b)),
99-
#[cfg(feature = "json")]
100-
AnyValueKind::Json(j) => AnyValueKind::Json(j.clone()),
101-
},
102-
}
103-
>>>>>>> 7d2161a5 (add argument mapping for sqlx and postgres)
10483
}
10584

10685
fn type_info(&self) -> Cow<'_, <Self::Database as Database>::TypeInfo> {
@@ -117,23 +96,7 @@ impl<'a> ValueRef<'a> for AnyValueRef<'a> {
11796

11897
fn to_owned(&self) -> <Self::Database as Database>::Value {
11998
AnyValue {
120-
<<<<<<< HEAD
12199
kind: self.kind.clone(),
122-
=======
123-
kind: match &self.kind {
124-
AnyValueKind::Null(k) => AnyValueKind::Null(*k),
125-
AnyValueKind::Bool(b) => AnyValueKind::Bool(*b),
126-
AnyValueKind::SmallInt(i) => AnyValueKind::SmallInt(*i),
127-
AnyValueKind::Integer(i) => AnyValueKind::Integer(*i),
128-
AnyValueKind::BigInt(i) => AnyValueKind::BigInt(*i),
129-
AnyValueKind::Real(r) => AnyValueKind::Real(*r),
130-
AnyValueKind::Double(d) => AnyValueKind::Double(*d),
131-
AnyValueKind::Text(t) => AnyValueKind::Text(Cow::Owned(t.to_string())),
132-
AnyValueKind::Blob(b) => AnyValueKind::Blob(Cow::Owned(b.to_vec())),
133-
#[cfg(feature = "json")]
134-
AnyValueKind::Json(j) => AnyValueKind::Json(j.clone()),
135-
},
136-
>>>>>>> 7d2161a5 (add argument mapping for sqlx and postgres)
137100
}
138101
}
139102

tests/any/any.rs

Lines changed: 82 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -208,105 +208,108 @@ async fn it_encodes_decodes_json() -> anyhow::Result<()> {
208208
.await?;
209209

210210
assert_eq!(result.0, test_data);
211-
#[sqlx_macros::test]
212-
async fn it_can_query_by_string_args() -> sqlx::Result<()> {
213-
install_default_drivers();
211+
#[sqlx_macros::test]
212+
async fn it_can_query_by_string_args() -> sqlx::Result<()> {
213+
install_default_drivers();
214214

215-
let mut conn = new::<Any>().await?;
215+
let mut conn = new::<Any>().await?;
216216

217-
let string = "Hello, world!".to_string();
218-
let ref tuple = ("Hello, world!".to_string(),);
217+
let string = "Hello, world!".to_string();
218+
let ref tuple = ("Hello, world!".to_string(),);
219219

220-
#[cfg(feature = "postgres")]
221-
const SQL: &str =
220+
#[cfg(feature = "postgres")]
221+
const SQL: &str =
222222
"SELECT 'Hello, world!' as string where 'Hello, world!' in ($1, $2, $3, $4, $5, $6, $7)";
223223

224-
#[cfg(not(feature = "postgres"))]
225-
const SQL: &str =
226-
"SELECT 'Hello, world!' as string where 'Hello, world!' in (?, ?, ?, ?, ?, ?, ?)";
224+
#[cfg(not(feature = "postgres"))]
225+
const SQL: &str =
226+
"SELECT 'Hello, world!' as string where 'Hello, world!' in (?, ?, ?, ?, ?, ?, ?)";
227227

228-
{
229-
let query = sqlx::query(SQL)
230-
// validate flexibility of lifetimes
231-
.bind(&string)
232-
.bind(&string[..])
233-
.bind(Some(&string))
234-
.bind(Some(&string[..]))
235-
.bind(&Option::<String>::None)
236-
.bind(&string.clone())
237-
.bind(&tuple.0); // should not get "temporary value is freed at the end of this statement" here
228+
{
229+
let query = sqlx::query(SQL)
230+
// validate flexibility of lifetimes
231+
.bind(&string)
232+
.bind(&string[..])
233+
.bind(Some(&string))
234+
.bind(Some(&string[..]))
235+
.bind(&Option::<String>::None)
236+
.bind(&string.clone())
237+
.bind(&tuple.0); // should not get "temporary value is freed at the end of this statement" here
238238

239-
let result = query.fetch_one(&mut conn).await?;
239+
let result = query.fetch_one(&mut conn).await?;
240240

241-
let column_0: String = result.try_get(0)?;
241+
let column_0: String = result.try_get(0)?;
242242

243-
assert_eq!(column_0, string);
244-
}
243+
assert_eq!(column_0, string);
244+
}
245245

246-
{
247-
let mut query = sqlx::query(SQL);
246+
{
247+
let mut query = sqlx::query(SQL);
248248

249-
let query = || -> Result<_, BoxDynError> {
250-
// validate flexibility of lifetimes
251-
query.try_bind(&string)?;
252-
query.try_bind(&string[..])?;
253-
query.try_bind(Some(&string))?;
254-
query.try_bind(Some(&string[..]))?;
255-
query.try_bind(&Option::<String>::None)?;
256-
query.try_bind(&string.clone())?;
257-
query.try_bind(&tuple.0)?;
249+
let query = || -> Result<_, BoxDynError> {
250+
// validate flexibility of lifetimes
251+
query.try_bind(&string)?;
252+
query.try_bind(&string[..])?;
253+
query.try_bind(Some(&string))?;
254+
query.try_bind(Some(&string[..]))?;
255+
query.try_bind(&Option::<String>::None)?;
256+
query.try_bind(&string.clone())?;
257+
query.try_bind(&tuple.0)?;
258258

259-
Ok(query)
260-
}()
261-
.map_err(Error::Encode)?;
259+
Ok(query)
260+
}()
261+
.map_err(Error::Encode)?;
262262

263-
let result = query.fetch_one(&mut conn).await?;
263+
let result = query.fetch_one(&mut conn).await?;
264264

265-
let column_0: String = result.try_get(0)?;
265+
let column_0: String = result.try_get(0)?;
266266

267-
assert_eq!(column_0, string);
267+
assert_eq!(column_0, string);
268+
}
268269
}
269-
#[cfg(feature = "json")]
270-
#[sqlx_macros::test]
271-
async fn it_encodes_decodes_json() -> anyhow::Result<()> {
272-
sqlx::any::install_default_drivers();
273270

274-
// Create new connection
275-
let mut conn = new::<Any>().await?;
271+
#[cfg(feature = "json")]
272+
#[sqlx_macros::test]
273+
async fn it_encodes_decodes_json() -> anyhow::Result<()> {
274+
sqlx::any::install_default_drivers();
275+
276+
// Create new connection
277+
let mut conn = new::<Any>().await?;
278+
279+
// Test with serde_json::Value
280+
let json_value = serde_json::json!({
281+
"name": "test",
282+
"value": 42,
283+
"items": [1, 2, 3]
284+
});
285+
286+
// This will work by encoding JSON as text and decoding it back
287+
let result: serde_json::Value = sqlx::query_scalar("SELECT ?")
288+
.bind(Json(&json_value))
289+
.fetch_one(&mut conn)
290+
.await?;
291+
292+
assert_eq!(result, json_value);
293+
294+
// Test with custom struct
295+
#[derive(Serialize, Deserialize, Debug, PartialEq)]
296+
struct TestData {
297+
name: String,
298+
count: i32,
299+
}
276300

277-
// Test with serde_json::Value
278-
let json_value = serde_json::json!({
279-
"name": "test",
280-
"value": 42,
281-
"items": [1, 2, 3]
282-
});
301+
let test_data = TestData {
302+
name: "example".to_string(),
303+
count: 100,
304+
};
283305

284-
// This will work by encoding JSON as text and decoding it back
285-
let result: serde_json::Value = sqlx::query_scalar("SELECT ?")
286-
.bind(Json(&json_value))
287-
.fetch_one(&mut conn)
288-
.await?;
306+
let result: Json<TestData> = sqlx::query_scalar("SELECT ?")
307+
.bind(Json(&test_data))
308+
.fetch_one(&mut conn)
309+
.await?;
289310

290-
assert_eq!(result, json_value);
311+
assert_eq!(result.0, test_data);
291312

292-
// Test with custom struct
293-
#[derive(Serialize, Deserialize, Debug, PartialEq)]
294-
struct TestData {
295-
name: String,
296-
count: i32,
313+
Ok(())
297314
}
298-
299-
let test_data = TestData {
300-
name: "example".to_string(),
301-
count: 100,
302-
};
303-
304-
let result: Json<TestData> = sqlx::query_scalar("SELECT ?")
305-
.bind(Json(&test_data))
306-
.fetch_one(&mut conn)
307-
.await?;
308-
309-
assert_eq!(result.0, test_data);
310-
311-
Ok(())
312315
}

0 commit comments

Comments
 (0)