|
1 | 1 | use std::borrow::Cow;
|
| 2 | +use std::rc::Rc; |
| 3 | +use std::sync::Arc; |
| 4 | + |
| 5 | +use sqlx_core::database::Database; |
2 | 6 |
|
3 | 7 | use crate::decode::Decode;
|
4 | 8 | use crate::encode::{Encode, IsNull};
|
@@ -30,84 +34,42 @@ impl<'r> Decode<'r, Sqlite> for &'r str {
|
30 | 34 | }
|
31 | 35 | }
|
32 | 36 |
|
33 |
| -impl Encode<'_, Sqlite> for Box<str> { |
34 |
| - fn encode(self, args: &mut Vec<SqliteArgumentValue<'_>>) -> Result<IsNull, BoxDynError> { |
35 |
| - args.push(SqliteArgumentValue::Text(Cow::Owned(self.into_string()))); |
36 |
| - |
37 |
| - Ok(IsNull::No) |
38 |
| - } |
39 |
| - |
40 |
| - fn encode_by_ref( |
41 |
| - &self, |
42 |
| - args: &mut Vec<SqliteArgumentValue<'_>>, |
43 |
| - ) -> Result<IsNull, BoxDynError> { |
44 |
| - args.push(SqliteArgumentValue::Text(Cow::Owned( |
45 |
| - self.clone().into_string(), |
46 |
| - ))); |
47 |
| - |
48 |
| - Ok(IsNull::No) |
49 |
| - } |
50 |
| -} |
51 |
| - |
52 | 37 | impl Type<Sqlite> for String {
|
53 | 38 | fn type_info() -> SqliteTypeInfo {
|
54 | 39 | <&str as Type<Sqlite>>::type_info()
|
55 | 40 | }
|
56 | 41 | }
|
57 | 42 |
|
58 |
| -impl<'q> Encode<'q, Sqlite> for String { |
59 |
| - fn encode(self, args: &mut Vec<SqliteArgumentValue<'q>>) -> Result<IsNull, BoxDynError> { |
60 |
| - args.push(SqliteArgumentValue::Text(Cow::Owned(self))); |
61 |
| - |
62 |
| - Ok(IsNull::No) |
63 |
| - } |
64 |
| - |
65 |
| - fn encode_by_ref( |
66 |
| - &self, |
67 |
| - args: &mut Vec<SqliteArgumentValue<'q>>, |
68 |
| - ) -> Result<IsNull, BoxDynError> { |
69 |
| - args.push(SqliteArgumentValue::Text(Cow::Owned(self.clone()))); |
70 |
| - |
71 |
| - Ok(IsNull::No) |
72 |
| - } |
73 |
| -} |
74 |
| - |
75 | 43 | impl<'r> Decode<'r, Sqlite> for String {
|
76 | 44 | fn decode(value: SqliteValueRef<'r>) -> Result<Self, BoxDynError> {
|
77 | 45 | value.text().map(ToOwned::to_owned)
|
78 | 46 | }
|
79 | 47 | }
|
80 | 48 |
|
81 |
| -impl<'q> Encode<'q, Sqlite> for Cow<'q, str> { |
82 |
| - fn encode(self, args: &mut Vec<SqliteArgumentValue<'q>>) -> Result<IsNull, BoxDynError> { |
83 |
| - args.push(SqliteArgumentValue::Text(self)); |
84 |
| - |
85 |
| - Ok(IsNull::No) |
86 |
| - } |
87 |
| - |
| 49 | +impl<'q> Encode<'q, Sqlite> for String { |
88 | 50 | fn encode_by_ref(
|
89 | 51 | &self,
|
90 | 52 | args: &mut Vec<SqliteArgumentValue<'q>>,
|
91 | 53 | ) -> Result<IsNull, BoxDynError> {
|
92 |
| - args.push(SqliteArgumentValue::Text(self.clone())); |
| 54 | + args.push(SqliteArgumentValue::Text(Cow::Owned(self.clone()))); |
93 | 55 |
|
94 | 56 | Ok(IsNull::No)
|
95 | 57 | }
|
96 |
| -} |
97 | 58 |
|
98 |
| -impl<'q> Encode<'q, Sqlite> for Cow<'q, [u8]> { |
99 |
| - fn encode(self, args: &mut Vec<SqliteArgumentValue<'q>>) -> Result<IsNull, BoxDynError> { |
100 |
| - args.push(SqliteArgumentValue::Blob(self)); |
101 |
| - |
102 |
| - Ok(IsNull::No) |
103 |
| - } |
104 |
| - |
105 |
| - fn encode_by_ref( |
106 |
| - &self, |
107 |
| - args: &mut Vec<SqliteArgumentValue<'q>>, |
108 |
| - ) -> Result<IsNull, BoxDynError> { |
109 |
| - args.push(SqliteArgumentValue::Blob(self.clone())); |
| 59 | + fn encode( |
| 60 | + self, |
| 61 | + buf: &mut <Sqlite as Database>::ArgumentBuffer<'q>, |
| 62 | + ) -> Result<IsNull, BoxDynError> |
| 63 | + where |
| 64 | + Self: Sized, |
| 65 | + { |
| 66 | + buf.push(SqliteArgumentValue::Text(Cow::Owned(self))); |
110 | 67 |
|
111 | 68 | Ok(IsNull::No)
|
112 | 69 | }
|
113 | 70 | }
|
| 71 | + |
| 72 | +forward_encode_impl!(Arc<str>, String, Sqlite, |s: &str| s.to_string()); |
| 73 | +forward_encode_impl!(Rc<str>, String, Sqlite, |s: &str| s.to_string()); |
| 74 | +forward_encode_impl!(Cow<'_, str>, String, Sqlite, |s: &str| s.to_string()); |
| 75 | +forward_encode_impl!(Box<str>, String, Sqlite, |s: &str| s.to_string()); |
0 commit comments