1- use std:: borrow:: Cow ;
2- use std:: rc:: Rc ;
3- use std:: sync:: Arc ;
4-
51use crate :: arguments:: SqliteArgumentsBuffer ;
62use crate :: decode:: Decode ;
73use crate :: encode:: { Encode , IsNull } ;
84use crate :: error:: BoxDynError ;
95use crate :: type_info:: DataType ;
106use crate :: types:: Type ;
117use crate :: { Sqlite , SqliteArgumentValue , SqliteTypeInfo , SqliteValueRef } ;
8+ use sqlx_core:: database:: Database ;
9+ use std:: borrow:: Cow ;
10+ use std:: rc:: Rc ;
11+ use std:: sync:: Arc ;
1212
1313impl Type < Sqlite > for str {
1414 fn type_info ( ) -> SqliteTypeInfo {
@@ -18,7 +18,7 @@ impl Type<Sqlite> for str {
1818
1919impl Encode < ' _ , Sqlite > for & ' _ str {
2020 fn encode_by_ref ( & self , args : & mut SqliteArgumentsBuffer ) -> Result < IsNull , BoxDynError > {
21- args. push ( SqliteArgumentValue :: Text ( self . to_string ( ) ) ) ;
21+ args. push ( SqliteArgumentValue :: Text ( Arc :: new ( self . to_string ( ) ) ) ) ;
2222
2323 Ok ( IsNull :: No )
2424 }
@@ -32,13 +32,13 @@ impl<'r> Decode<'r, Sqlite> for &'r str {
3232
3333impl Encode < ' _ , Sqlite > for Box < str > {
3434 fn encode ( self , args : & mut SqliteArgumentsBuffer ) -> Result < IsNull , BoxDynError > {
35- args. push ( SqliteArgumentValue :: Text ( self . into_string ( ) ) ) ;
35+ args. push ( SqliteArgumentValue :: TextSlice ( Arc :: from ( self ) ) ) ;
3636
3737 Ok ( IsNull :: No )
3838 }
3939
4040 fn encode_by_ref ( & self , args : & mut SqliteArgumentsBuffer ) -> Result < IsNull , BoxDynError > {
41- args. push ( SqliteArgumentValue :: Text ( self . to_string ( ) ) ) ;
41+ args. push ( SqliteArgumentValue :: Text ( Arc :: new ( self . to_string ( ) ) ) ) ;
4242
4343 Ok ( IsNull :: No )
4444 }
@@ -52,13 +52,13 @@ impl Type<Sqlite> for String {
5252
5353impl Encode < ' _ , Sqlite > for String {
5454 fn encode ( self , args : & mut SqliteArgumentsBuffer ) -> Result < IsNull , BoxDynError > {
55- args. push ( SqliteArgumentValue :: Text ( self ) ) ;
55+ args. push ( SqliteArgumentValue :: Text ( Arc :: new ( self ) ) ) ;
5656
5757 Ok ( IsNull :: No )
5858 }
5959
6060 fn encode_by_ref ( & self , args : & mut SqliteArgumentsBuffer ) -> Result < IsNull , BoxDynError > {
61- args. push ( SqliteArgumentValue :: Text ( self . clone ( ) ) ) ;
61+ args. push ( SqliteArgumentValue :: Text ( Arc :: new ( self . clone ( ) ) ) ) ;
6262
6363 Ok ( IsNull :: No )
6464 }
@@ -72,19 +72,31 @@ impl<'r> Decode<'r, Sqlite> for String {
7272
7373impl Encode < ' _ , Sqlite > for Cow < ' _ , str > {
7474 fn encode ( self , args : & mut SqliteArgumentsBuffer ) -> Result < IsNull , BoxDynError > {
75- args. push ( SqliteArgumentValue :: Text ( self . into ( ) ) ) ;
75+ args. push ( SqliteArgumentValue :: Text ( Arc :: new ( self . into ( ) ) ) ) ;
7676
7777 Ok ( IsNull :: No )
7878 }
7979
8080 fn encode_by_ref ( & self , args : & mut SqliteArgumentsBuffer ) -> Result < IsNull , BoxDynError > {
81- args. push ( SqliteArgumentValue :: Text ( self . to_string ( ) ) ) ;
81+ args. push ( SqliteArgumentValue :: Text ( Arc :: new ( self . to_string ( ) ) ) ) ;
8282
8383 Ok ( IsNull :: No )
8484 }
8585}
8686
8787impl Encode < ' _ , Sqlite > for Arc < str > {
88+ fn encode (
89+ self ,
90+ args : & mut <Sqlite as Database >:: ArgumentBuffer < ' _ > ,
91+ ) -> Result < IsNull , BoxDynError >
92+ where
93+ Self : Sized ,
94+ {
95+ args. push ( SqliteArgumentValue :: TextSlice ( self ) ) ;
96+
97+ Ok ( IsNull :: No )
98+ }
99+
88100 fn encode_by_ref ( & self , args : & mut SqliteArgumentsBuffer ) -> Result < IsNull , BoxDynError > {
89101 <String as Encode < ' _ , Sqlite > >:: encode ( self . to_string ( ) , args)
90102 }
0 commit comments