You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+43-7Lines changed: 43 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,14 +14,38 @@ cargo add spiceai
14
14
15
15
<!-- NOTE: If you're changing the code examples below, make sure you update `tests/readme_test.rs`. -->
16
16
17
-
### New client
17
+
### Usage with locally running [spice runtime](https://github.com/spiceai/spiceai)
18
+
19
+
Follow the [quiqstart guide](https://github.com/spiceai/spiceai?tab=readme-ov-file#%EF%B8%8F-quickstart-local-machine) to install and run spice locally
20
+
21
+
```rust
22
+
usespiceai::ClientBuilder;
23
+
24
+
#[tokio::main]
25
+
asyncfnmain() {
26
+
letmutclient=ClientBuilder::new()
27
+
.flight_url("http://localhost:50051")
28
+
.build()
29
+
.await
30
+
.unwrap();
31
+
32
+
letdata=client.query("SELECT trip_distance, total_amount FROM taxi_trips ORDER BY trip_distance DESC LIMIT 10;").await;
/// Queries the Spice Flight endpoint with the given SQL query.
68
66
/// ```
69
67
/// # use spiceai::Client;
@@ -95,3 +93,100 @@ impl SpiceClient {
95
93
self.firecache.query(query).await
96
94
}
97
95
}
96
+
97
+
/// Builder for creating a `SpiceClient`.
98
+
///
99
+
/// By default the `SpiceClient` will use local spice runtime flight endpoint.
100
+
/// Follow [spiceai quickstart](https://github.com/spiceai/spiceai?tab=readme-ov-file#%EF%B8%8F-quickstart-local-machine) to setup local spice runtime.
101
+
/// ```
102
+
/// # use spiceai::ClientBuilder;
103
+
/// #
104
+
/// # #[tokio::main]
105
+
/// # async fn main() {
106
+
/// # let mut client = ClientBuilder::new()
107
+
/// # .build()
108
+
/// # .await
109
+
/// # .unwrap();
110
+
/// # }
111
+
/// ```
112
+
/// To use default Spice.ai Cloud endpoints, you can use the `with_spiceai_cloud()` method.
113
+
///
114
+
/// ```
115
+
/// # use spiceai::ClientBuilder;
116
+
/// #
117
+
/// # #[tokio::main]
118
+
/// # async fn main() {
119
+
/// # let mut client = ClientBuilder::new()
120
+
/// # .api_key("API_KEY")
121
+
/// # .use_spiceai_cloud()
122
+
/// # .build()
123
+
/// # .await
124
+
/// # .unwrap();
125
+
/// # }
126
+
/// ```
127
+
///
128
+
pubstructSpiceClientBuilder{
129
+
api_key:Option<String>,
130
+
firecache_url:Option<String>,
131
+
flight_url:Option<String>,
132
+
}
133
+
134
+
implDefaultforSpiceClientBuilder{
135
+
fndefault() -> Self{
136
+
Self::new()
137
+
}
138
+
}
139
+
140
+
implSpiceClientBuilder{
141
+
pubfnnew() -> Self{
142
+
Self{
143
+
api_key:None,
144
+
firecache_url:None,
145
+
flight_url:None,
146
+
}
147
+
}
148
+
149
+
/// Configures the `SpiceClient` to use the given API key.
150
+
pubfnapi_key(mutself,api_key:&str) -> Self{
151
+
self.api_key = Some(api_key.to_string());
152
+
self
153
+
}
154
+
155
+
/// Configures the `SpiceClient` to use the given Spice Firecache endpoint.
0 commit comments