@@ -29,8 +29,9 @@ pub enum ConnectionError {
29
29
/// Container for query parameters
30
30
/// This API has different endpoints and MIME types for different requests
31
31
struct QueryContext {
32
- path : & ' static str ,
32
+ path : String ,
33
33
accept_mime : & ' static str ,
34
+ method : reqwest:: Method
34
35
}
35
36
36
37
pub enum QueryType {
@@ -39,30 +40,40 @@ pub enum QueryType {
39
40
CloseSession ,
40
41
JsonQuery ,
41
42
ArrowQuery ,
43
+ ArrowQueryResult ( String ) ,
42
44
}
43
-
44
45
impl QueryType {
45
- const fn query_context ( & self ) -> QueryContext {
46
+ fn query_context ( & self ) -> QueryContext {
46
47
match self {
47
48
Self :: LoginRequest => QueryContext {
48
- path : "session/v1/login-request" ,
49
+ path : "session/v1/login-request" . to_string ( ) ,
49
50
accept_mime : "application/json" ,
51
+ method : reqwest:: Method :: POST ,
50
52
} ,
51
53
Self :: TokenRequest => QueryContext {
52
- path : "/session/token-request" ,
54
+ path : "/session/token-request" . to_string ( ) ,
53
55
accept_mime : "application/snowflake" ,
56
+ method : reqwest:: Method :: POST ,
54
57
} ,
55
58
Self :: CloseSession => QueryContext {
56
- path : "session" ,
59
+ path : "session" . to_string ( ) ,
57
60
accept_mime : "application/snowflake" ,
61
+ method : reqwest:: Method :: POST ,
58
62
} ,
59
63
Self :: JsonQuery => QueryContext {
60
- path : "queries/v1/query-request" ,
64
+ path : "queries/v1/query-request" . to_string ( ) ,
61
65
accept_mime : "application/json" ,
66
+ method : reqwest:: Method :: POST ,
62
67
} ,
63
68
Self :: ArrowQuery => QueryContext {
64
- path : "queries/v1/query-request" ,
69
+ path : "queries/v1/query-request" . to_string ( ) ,
70
+ accept_mime : "application/snowflake" ,
71
+ method : reqwest:: Method :: POST ,
72
+ } ,
73
+ Self :: ArrowQueryResult ( query_result_url) => QueryContext {
74
+ path : query_result_url. to_string ( ) ,
65
75
accept_mime : "application/snowflake" ,
76
+ method : reqwest:: Method :: GET ,
66
77
} ,
67
78
}
68
79
}
@@ -163,14 +174,22 @@ impl Connection {
163
174
}
164
175
165
176
// todo: persist client to use connection polling
166
- let resp = self
167
- . client
168
- . post ( url)
169
- . headers ( headers)
170
- . json ( & body)
171
- . send ( )
172
- . await ?;
173
-
177
+ let resp = match context. method {
178
+ reqwest:: Method :: POST => self
179
+ . client
180
+ . post ( url)
181
+ . headers ( headers)
182
+ . json ( & body)
183
+ . send ( )
184
+ . await ?,
185
+ reqwest:: Method :: GET => self
186
+ . client
187
+ . get ( url)
188
+ . headers ( headers)
189
+ . send ( )
190
+ . await ?,
191
+ _ => panic ! ( "Unsupported method" ) ,
192
+ } ;
174
193
Ok ( resp. json :: < R > ( ) . await ?)
175
194
}
176
195
0 commit comments