@@ -29,8 +29,9 @@ pub enum ConnectionError {
2929/// Container for query parameters
3030/// This API has different endpoints and MIME types for different requests
3131struct QueryContext {
32- path : & ' static str ,
32+ path : String ,
3333 accept_mime : & ' static str ,
34+ method : reqwest:: Method
3435}
3536
3637pub enum QueryType {
@@ -39,30 +40,40 @@ pub enum QueryType {
3940 CloseSession ,
4041 JsonQuery ,
4142 ArrowQuery ,
43+ ArrowQueryResult ( String ) ,
4244}
43-
4445impl QueryType {
45- const fn query_context ( & self ) -> QueryContext {
46+ fn query_context ( & self ) -> QueryContext {
4647 match self {
4748 Self :: LoginRequest => QueryContext {
48- path : "session/v1/login-request" ,
49+ path : "session/v1/login-request" . to_string ( ) ,
4950 accept_mime : "application/json" ,
51+ method : reqwest:: Method :: POST ,
5052 } ,
5153 Self :: TokenRequest => QueryContext {
52- path : "/session/token-request" ,
54+ path : "/session/token-request" . to_string ( ) ,
5355 accept_mime : "application/snowflake" ,
56+ method : reqwest:: Method :: POST ,
5457 } ,
5558 Self :: CloseSession => QueryContext {
56- path : "session" ,
59+ path : "session" . to_string ( ) ,
5760 accept_mime : "application/snowflake" ,
61+ method : reqwest:: Method :: POST ,
5862 } ,
5963 Self :: JsonQuery => QueryContext {
60- path : "queries/v1/query-request" ,
64+ path : "queries/v1/query-request" . to_string ( ) ,
6165 accept_mime : "application/json" ,
66+ method : reqwest:: Method :: POST ,
6267 } ,
6368 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 ( ) ,
6575 accept_mime : "application/snowflake" ,
76+ method : reqwest:: Method :: GET ,
6677 } ,
6778 }
6879 }
@@ -163,14 +174,22 @@ impl Connection {
163174 }
164175
165176 // 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+ } ;
174193 Ok ( resp. json :: < R > ( ) . await ?)
175194 }
176195
0 commit comments