Executes SQL statements in SQL Server, returning a [`Stream`] of resulting rows. Passthrough method for [`tiberius::Client::query`].
(
&'c mut self,
query: Q,
params: &[&dyn tiberius::ToSql],
)
| 218 | /// |
| 219 | /// Passthrough method for [`tiberius::Client::query`]. |
| 220 | pub fn query_streaming<'c, 'q, Q>( |
| 221 | &'c mut self, |
| 222 | query: Q, |
| 223 | params: &[&dyn tiberius::ToSql], |
| 224 | ) -> impl Stream<Item = Result<tiberius::Row, SqlServerError>> + Send + use<'c, Q> |
| 225 | where |
| 226 | Q: Into<Cow<'q, str>>, |
| 227 | { |
| 228 | let (tx, rx) = tokio::sync::oneshot::channel(); |
| 229 | let params = params |
| 230 | .iter() |
| 231 | .map(|p| OwnedColumnData::from(p.to_sql())) |
| 232 | .collect(); |
| 233 | let kind = RequestKind::QueryStreamed { |
| 234 | query: query.into().to_string(), |
| 235 | params, |
| 236 | }; |
| 237 | |
| 238 | // Make our initial request which will return a Stream of Rows. |
| 239 | let request_future = async move { |
| 240 | self.tx |
| 241 | .send(Request { tx, kind }) |
| 242 | .context("sending request")?; |
| 243 | |
| 244 | let response = rx.await.context("channel")??; |
| 245 | match response { |
| 246 | Response::RowStream { stream } => { |
| 247 | Ok(tokio_stream::wrappers::ReceiverStream::new(stream)) |
| 248 | } |
| 249 | other @ Response::Execute { .. } | other @ Response::Rows(_) => { |
| 250 | Err(SqlServerError::ProgrammingError(format!( |
| 251 | "expected Response::Rows, got {other:?}" |
| 252 | ))) |
| 253 | } |
| 254 | } |
| 255 | }; |
| 256 | |
| 257 | // "flatten" our initial request into the returned stream. |
| 258 | futures::stream::once(request_future).try_flatten() |
| 259 | } |
| 260 | |
| 261 | /// Executes multiple queries, delimited with `;` and return multiple |
| 262 | /// result sets; one for each query. |