Warning
SingleStore 9.0 gives you the opportunity to preview, evaluate, and provide feedback on new and upcoming features prior to their general availability. In the interim, SingleStore 8.9 is recommended for production workloads, which can later be upgraded to SingleStore 9.0.
Connect with Rust
To connect SingleStore with Rust, use SQLx with its MySQL feature.
[package]name = "rust-singlestore-connect"version = "0.1.0"edition = "2021"[dependencies]sqlx = { version = "0.5", features = ["runtime-tokio-native-tls", "mysql"] }tokio = { version = "1", features = ["full"] }
For more information, see SQLx Docs.
Here's a sample main.
use sqlx::mysql::{MySqlConnectOptions, MySqlPoolOptions};#[tokio::main]async fn main() -> Result<(), sqlx::Error> {let opts = MySqlConnectOptions::new().host("svc-ab8077f6-7b03-4ba3-b557-063c53eff943-ddl.aws-oregon-2.svc.singlestore.com").username("admin").password("PASSWORD");let pool = MySqlPoolOptions::new().connect_with(opts).await?;let row: (i64,) = sqlx::query_as("SELECT ?").bind(150_i64).fetch_one(&pool).await?;assert_eq!(row.0, 150);Ok(())}
Last modified: April 7, 2023