@@ -27,8 +27,9 @@ use crate::{
2727} ;
2828use client_request:: {
2929 ClientRequest , ListEventTypesRequest , ListSubjectsRequest , ObserveEventsRequest ,
30- OneShotRequest , PingRequest , ReadEventsRequest , RegisterEventSchemaRequest , StreamingRequest ,
31- VerifyApiTokenRequest , WriteEventsRequest , list_event_types:: EventType ,
30+ OneShotRequest , PingRequest , ReadEventsRequest , RegisterEventSchemaRequest ,
31+ RunEventqlQueryRequest , StreamingRequest , VerifyApiTokenRequest , WriteEventsRequest ,
32+ list_event_types:: EventType ,
3233} ;
3334use futures:: Stream ;
3435pub use precondition:: Precondition ;
@@ -425,4 +426,37 @@ impl Client {
425426 } )
426427 . await
427428 }
429+
430+ /// Run an eventql query against the DB.
431+ ///
432+ /// ```
433+ /// use eventsourcingdb_client_rust::event::EventCandidate;
434+ /// use futures::StreamExt;
435+ /// # use serde_json::json;
436+ /// # tokio_test::block_on(async {
437+ /// # let container = eventsourcingdb_client_rust::container::Container::start_default().await.unwrap();
438+ /// let db_url = "http://localhost:3000/";
439+ /// let api_token = "secrettoken";
440+ /// # let db_url = container.get_base_url().await.unwrap();
441+ /// # let api_token = container.get_api_token();
442+ /// let client = eventsourcingdb_client_rust::client::Client::new(db_url, api_token);
443+ /// let query = "FROM e IN events ORDER BY e.time DESC TOP 100 PROJECT INTO e";
444+ /// let mut row_stream = client.run_eventql_query(query).await.expect("Failed to list event types");
445+ /// while let Some(row) = row_stream.next().await {
446+ /// println!("Found row {:?}", row.expect("Error while reading row"));
447+ /// }
448+ /// # })
449+ /// ```
450+ ///
451+ /// # Errors
452+ /// This function will return an error if the request fails or if the URL is invalid.
453+ pub async fn run_eventql_query (
454+ & self ,
455+ query : & str ,
456+ ) -> Result < impl Stream < Item = Result < serde_json:: Value , ClientError > > , ClientError > {
457+ let response = self
458+ . request_streaming ( RunEventqlQueryRequest { query } )
459+ . await ?;
460+ Ok ( response)
461+ }
428462}
0 commit comments