Create a prepared statement object.
(
&mut self,
query: String,
transaction_id: Option<Bytes>,
)
| 370 | |
| 371 | /// Create a prepared statement object. |
| 372 | pub async fn prepare( |
| 373 | &mut self, |
| 374 | query: String, |
| 375 | transaction_id: Option<Bytes>, |
| 376 | ) -> Result<PreparedStatement<T>> |
| 377 | where |
| 378 | T: Clone, |
| 379 | { |
| 380 | let cmd = ActionCreatePreparedStatementRequest { |
| 381 | query, |
| 382 | transaction_id, |
| 383 | }; |
| 384 | let action = Action { |
| 385 | r#type: CREATE_PREPARED_STATEMENT.to_string(), |
| 386 | body: cmd.as_any().encode_to_vec().into(), |
| 387 | }; |
| 388 | let req = self.set_request_headers(action.into_request())?; |
| 389 | let mut result = self.flight_client.do_action(req).await?.into_inner(); |
| 390 | let result = result.message().await?.unwrap(); |
| 391 | let any = Any::decode(&*result.body)?; |
| 392 | let prepared_result: ActionCreatePreparedStatementResult = any.unpack()?.unwrap(); |
| 393 | let dataset_schema = match prepared_result.dataset_schema.len() { |
| 394 | 0 => Schema::empty(), |
| 395 | _ => Schema::try_from(IpcMessage(prepared_result.dataset_schema))?, |
| 396 | }; |
| 397 | let parameter_schema = match prepared_result.parameter_schema.len() { |
| 398 | 0 => Schema::empty(), |
| 399 | _ => Schema::try_from(IpcMessage(prepared_result.parameter_schema))?, |
| 400 | }; |
| 401 | Ok(PreparedStatement::new( |
| 402 | self.clone(), |
| 403 | prepared_result.prepared_statement_handle, |
| 404 | dataset_schema, |
| 405 | parameter_schema, |
| 406 | )) |
| 407 | } |
| 408 | |
| 409 | /// Request to begin a transaction. |
| 410 | pub async fn begin_transaction(&mut self) -> Result<Bytes> { |