@@ -594,8 +594,8 @@ impl<'a> FromSql<'a> for &'a [u8] {
594
594
}
595
595
596
596
impl < ' a > FromSql < ' a > for String {
597
- fn from_sql ( _ : & Type , raw : & ' a [ u8 ] ) -> Result < String , Box < dyn Error + Sync + Send > > {
598
- types :: text_from_sql ( raw) . map ( ToString :: to_string)
597
+ fn from_sql ( ty : & Type , raw : & ' a [ u8 ] ) -> Result < String , Box < dyn Error + Sync + Send > > {
598
+ < & str as FromSql > :: from_sql ( ty , raw) . map ( ToString :: to_string)
599
599
}
600
600
601
601
fn accepts ( ty : & Type ) -> bool {
@@ -604,8 +604,8 @@ impl<'a> FromSql<'a> for String {
604
604
}
605
605
606
606
impl < ' a > FromSql < ' a > for Box < str > {
607
- fn from_sql ( _ : & Type , raw : & ' a [ u8 ] ) -> Result < Box < str > , Box < dyn Error + Sync + Send > > {
608
- types :: text_from_sql ( raw)
607
+ fn from_sql ( ty : & Type , raw : & ' a [ u8 ] ) -> Result < Box < str > , Box < dyn Error + Sync + Send > > {
608
+ < & str as FromSql > :: from_sql ( ty , raw)
609
609
. map ( ToString :: to_string)
610
610
. map ( String :: into_boxed_str)
611
611
}
@@ -616,14 +616,26 @@ impl<'a> FromSql<'a> for Box<str> {
616
616
}
617
617
618
618
impl < ' a > FromSql < ' a > for & ' a str {
619
- fn from_sql ( _: & Type , raw : & ' a [ u8 ] ) -> Result < & ' a str , Box < dyn Error + Sync + Send > > {
620
- types:: text_from_sql ( raw)
619
+ fn from_sql ( ty : & Type , raw : & ' a [ u8 ] ) -> Result < & ' a str , Box < dyn Error + Sync + Send > > {
620
+ match * ty {
621
+ ref ty if (
622
+ ty. name ( ) == "ltree" ||
623
+ ty. name ( ) == "lquery" ||
624
+ ty. name ( ) == "ltxtquery"
625
+ ) => types:: ltree_from_sql ( raw) ,
626
+ _ => types:: text_from_sql ( raw)
627
+ }
621
628
}
622
629
623
630
fn accepts ( ty : & Type ) -> bool {
624
631
match * ty {
625
632
Type :: VARCHAR | Type :: TEXT | Type :: BPCHAR | Type :: NAME | Type :: UNKNOWN => true ,
626
- ref ty if ty. name ( ) == "citext" => true ,
633
+ ref ty if (
634
+ ty. name ( ) == "citext" ||
635
+ ty. name ( ) == "ltree" ||
636
+ ty. name ( ) == "lquery" ||
637
+ ty. name ( ) == "ltxtquery"
638
+ ) => true ,
627
639
_ => false ,
628
640
}
629
641
}
@@ -924,15 +936,27 @@ impl ToSql for Vec<u8> {
924
936
}
925
937
926
938
impl < ' a > ToSql for & ' a str {
927
- fn to_sql ( & self , _: & Type , w : & mut BytesMut ) -> Result < IsNull , Box < dyn Error + Sync + Send > > {
928
- types:: text_to_sql ( * self , w) ;
939
+ fn to_sql ( & self , ty : & Type , w : & mut BytesMut ) -> Result < IsNull , Box < dyn Error + Sync + Send > > {
940
+ match ty {
941
+ ref ty if (
942
+ ty. name ( ) == "ltree" ||
943
+ ty. name ( ) == "lquery" ||
944
+ ty. name ( ) == "ltxtquery"
945
+ ) => types:: ltree_to_sql ( * self , w) ,
946
+ _ => types:: text_to_sql ( * self , w)
947
+ }
929
948
Ok ( IsNull :: No )
930
949
}
931
950
932
951
fn accepts ( ty : & Type ) -> bool {
933
952
match * ty {
934
953
Type :: VARCHAR | Type :: TEXT | Type :: BPCHAR | Type :: NAME | Type :: UNKNOWN => true ,
935
- ref ty if ty. name ( ) == "citext" => true ,
954
+ ref ty if (
955
+ ty. name ( ) == "citext" ||
956
+ ty. name ( ) == "ltree" ||
957
+ ty. name ( ) == "lquery" ||
958
+ ty. name ( ) == "ltxtquery"
959
+ ) => true ,
936
960
_ => false ,
937
961
}
938
962
}
0 commit comments