MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / query_streaming

Method query_streaming

src/sql-server-util/src/lib.rs:220–259  ·  view source on GitHub ↗

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],
    )

Source from the content-addressed store, hash-verified

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.

Callers 2

get_changes_ascFunction · 0.80
snapshotFunction · 0.80

Calls 8

channelFunction · 0.85
collectMethod · 0.45
mapMethod · 0.45
iterMethod · 0.45
to_sqlMethod · 0.45
to_stringMethod · 0.45
contextMethod · 0.45
sendMethod · 0.45

Tested by 2

get_changes_ascFunction · 0.64
snapshotFunction · 0.64