@@ -2,16 +2,13 @@ use crate::column::ColumnIndex;
2
2
use crate :: error:: Error ;
3
3
use crate :: message:: DataRow ;
4
4
use crate :: statement:: PgStatementMetadata ;
5
- use crate :: type_info:: PgType ;
6
- use crate :: types:: * ;
7
5
use crate :: value:: PgValueFormat ;
8
6
use crate :: { PgColumn , PgValueRef , Postgres } ;
9
- use std:: fmt:: { Debug , DebugMap } ;
10
- use std:: sync:: Arc ;
11
-
12
- use sqlx_core:: decode:: Decode ;
13
- use sqlx_core:: ext:: ustr:: UStr ;
14
7
pub ( crate ) use sqlx_core:: row:: Row ;
8
+ use sqlx_core:: type_checking:: TypeChecking ;
9
+ use sqlx_core:: value:: ValueRef ;
10
+ use std:: fmt:: Debug ;
11
+ use std:: sync:: Arc ;
15
12
16
13
/// Implementation of [`Row`] for PostgreSQL.
17
14
pub struct PgRow {
@@ -60,98 +57,16 @@ impl Debug for PgRow {
60
57
61
58
let mut debug_map = f. debug_map ( ) ;
62
59
for ( index, column) in self . columns ( ) . iter ( ) . enumerate ( ) {
63
- add_debug_entry ( & mut debug_map, self , index, column) ;
60
+ if let Ok ( value) = self . try_get_raw ( index) {
61
+ debug_map. entry (
62
+ & column. name ,
63
+ & Postgres :: fmt_value_debug ( & <PgValueRef as ValueRef >:: to_owned ( & value) ) ,
64
+ ) ;
65
+ } else {
66
+ debug_map. entry ( & column. name , & "ERROR" ) ;
67
+ }
64
68
}
65
69
66
70
debug_map. finish ( )
67
71
}
68
72
}
69
-
70
- macro_rules! debug_types {
71
- { $( $enum: ident:: $variant: ident => $type: ty) ,* } => {
72
- fn add_debug_entry(
73
- debug_map: & mut DebugMap <' _, ' _>,
74
- row: & PgRow ,
75
- index: usize ,
76
- column: & PgColumn ) {
77
- let name = & column. name;
78
- match row. try_get_raw( index) {
79
- Ok ( value) => {
80
- match column. type_info. 0 {
81
- $(
82
- $enum:: $variant => add_decoded_entry:: <$type>( debug_map, value, name) ,
83
- ) *
84
- _ => add_raw_entry( debug_map, value, name)
85
- }
86
- }
87
- _ => {
88
- debug_map. entry( name, & "NOT FOUND" ) ;
89
- }
90
- }
91
-
92
- }
93
- }
94
- }
95
-
96
- fn add_decoded_entry < ' r , T : Decode < ' r , Postgres > + Debug > (
97
- debug_map : & mut DebugMap < ' _ , ' _ > ,
98
- value : PgValueRef < ' r > ,
99
- name : & UStr ,
100
- ) {
101
- match T :: decode ( value. clone ( ) ) {
102
- Ok ( decoded_value) => {
103
- debug_map. entry ( name, & decoded_value) ;
104
- }
105
- _ => {
106
- add_raw_entry ( debug_map, value, name) ;
107
- }
108
- } ;
109
- }
110
-
111
- fn add_raw_entry ( debug_map : & mut DebugMap < ' _ , ' _ > , value : PgValueRef , name : & UStr ) {
112
- match value. format {
113
- PgValueFormat :: Text => debug_map. entry ( name, & value. as_str ( ) . unwrap_or_default ( ) ) ,
114
- PgValueFormat :: Binary => debug_map. entry ( name, & value. as_bytes ( ) . unwrap_or_default ( ) ) ,
115
- } ;
116
- }
117
-
118
- debug_types ! {
119
- PgType :: Money => PgMoney ,
120
- PgType :: MoneyArray => Vec <PgMoney >,
121
- PgType :: Void => ( ) ,
122
- PgType :: Bool => bool ,
123
- PgType :: BoolArray => Vec <bool >,
124
- PgType :: Float4 => f32 ,
125
- PgType :: Float4Array => Vec <f32 >,
126
- PgType :: Float8 => f64 ,
127
- PgType :: Int4Range => PgRange <i32 >,
128
- PgType :: Int8Range => PgRange <i64 >,
129
- PgType :: Text => String ,
130
- PgType :: TextArray => Vec <String >,
131
- PgType :: Bpchar => String ,
132
- PgType :: BpcharArray => Vec <String >,
133
- PgType :: Name => String ,
134
- PgType :: NameArray => Vec <String >,
135
- PgType :: Varchar => String ,
136
- PgType :: VarcharArray => Vec <String >,
137
- PgType :: Interval => PgInterval ,
138
- PgType :: IntervalArray => Vec <PgInterval >,
139
- PgType :: Oid => Oid ,
140
- PgType :: OidArray => Vec <Oid >,
141
- PgType :: Char => i8 ,
142
- PgType :: CharArray => Vec <i8 >,
143
- PgType :: Int2 => i16 ,
144
- PgType :: Int2Array => Vec <i16 >,
145
- PgType :: Int4 => i32 ,
146
- PgType :: Int4Array => Vec <i32 >,
147
- PgType :: Int8 => i64 ,
148
- PgType :: Int8Array => Vec <i64 >,
149
- PgType :: Timestamp => i64 ,
150
- PgType :: TimestampArray => Vec <i64 >,
151
- PgType :: Time => i64 ,
152
- PgType :: TimeArray => Vec <i64 >,
153
- PgType :: Timestamptz => i64 ,
154
- PgType :: TimestamptzArray => Vec <i64 >,
155
- PgType :: Date => i32 ,
156
- PgType :: DateArray => Vec <i32 >
157
- }
0 commit comments