summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rust/Cargo.toml4
-rw-r--r--rust/src/main.rs34
2 files changed, 36 insertions, 2 deletions
diff --git a/rust/Cargo.toml b/rust/Cargo.toml
index f9fe11c..6fdfa00 100644
--- a/rust/Cargo.toml
+++ b/rust/Cargo.toml
@@ -4,3 +4,7 @@ version = "0.1.0"
edition = "2021"
[dependencies]
+actix-web = { version = "4.9.0"}
+sqlx = { version = "0.8.2", features = ["mysql", "macros" , "runtime-tokio"] }
+serde = { version = "1.0.210", features = ["derive"] }
+tokio = "1.40.0"
diff --git a/rust/src/main.rs b/rust/src/main.rs
index 486aa6f..2ccdcee 100644
--- a/rust/src/main.rs
+++ b/rust/src/main.rs
@@ -1,5 +1,35 @@
mod structs;
-fn main() {
- println!("Hello, world!");
+use actix_web::{web, App, HttpServer};
+use sqlx::mysql::{MySqlPool, MySqlPoolOptions};
+
+#[derive(Clone)]
+struct AppState {
+ pool: MySqlPool,
+}
+
+#[actix_web::main]
+async fn main() -> std::io::Result<()> {
+ const DB_URL: &str = "mysql://root:@127.0.0.1:3306/balalaika";
+
+ let pool: MySqlPool = MySqlPoolOptions::new()
+ .max_connections(10)
+ .connect(DB_URL)
+ .await
+ .unwrap();
+
+ let app_state = AppState { pool };
+
+ HttpServer::new(move || {
+ App::new()
+ .app_data(web::Data::new(app_state.clone()))
+ .route("/", web::get().to(root))
+ })
+ .bind(("127.0.0.1", 8000))?
+ .run()
+ .await
+}
+
+async fn root() -> String {
+ String::from("Server is up and running")
}