File tree Expand file tree Collapse file tree 3 files changed +26
-3
lines changed Expand file tree Collapse file tree 3 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ use super::SqlUpdateModelValue;
77
88pub trait SqlUpdateModel {
99 fn get_column_name ( no : usize ) -> ColumnName ;
10- fn get_field_value ( & self , no : usize ) -> SqlUpdateModelValue ;
10+ fn get_field_value < ' s > ( & ' s self , no : usize ) -> SqlUpdateModelValue < ' s > ;
1111 fn get_fields_amount ( ) -> usize ;
1212
1313 fn get_primary_key_as_single_string ( & self ) -> String ;
Original file line number Diff line number Diff line change @@ -20,8 +20,15 @@ impl SqlUpdateValueProvider for String {
2020 fn get_update_value (
2121 & self ,
2222 params : & mut SqlValues ,
23- _metadata : & Option < SqlValueMetadata > ,
23+ metadata : & Option < SqlValueMetadata > ,
2424 ) -> SqlUpdateValue {
25+ if let Some ( metadata) = metadata {
26+ if metadata. is_json_or_jsonb ( ) {
27+ let index = params. push ( self . into ( ) ) ;
28+ return SqlUpdateValue :: Json ( index) ;
29+ }
30+ }
31+
2532 let index = params. push ( self . into ( ) ) ;
2633 SqlUpdateValue :: Index ( index)
2734 }
@@ -31,8 +38,14 @@ impl<'s> SqlUpdateValueProvider for &'s str {
3138 fn get_update_value (
3239 & self ,
3340 params : & mut SqlValues ,
34- _metadata : & Option < SqlValueMetadata > ,
41+ metadata : & Option < SqlValueMetadata > ,
3542 ) -> SqlUpdateValue {
43+ if let Some ( metadata) = metadata {
44+ if metadata. is_json_or_jsonb ( ) {
45+ let index = params. push ( ( * self ) . into ( ) ) ;
46+ return SqlUpdateValue :: Json ( index) ;
47+ }
48+ }
3649 let index = params. push ( ( * self ) . into ( ) ) ;
3750 SqlUpdateValue :: Index ( index)
3851 }
Original file line number Diff line number Diff line change @@ -4,3 +4,13 @@ pub struct SqlValueMetadata {
44 pub operator : Option < & ' static str > ,
55 pub wrap_column_name : Option < & ' static str > ,
66}
7+
8+ impl SqlValueMetadata {
9+ pub fn is_json_or_jsonb ( & self ) -> bool {
10+ if let Some ( sql_type) = self . sql_type {
11+ return sql_type. eq_ignore_ascii_case ( "json" ) || sql_type. eq_ignore_ascii_case ( "jsonb" ) ;
12+ }
13+
14+ false
15+ }
16+ }
You can’t perform that action at this time.
0 commit comments