summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorniliara-edu <nil.jimeno@estudiant.fjaverianas.com>2024-09-26 13:56:04 +0200
committerniliara-edu <nil.jimeno@estudiant.fjaverianas.com>2024-09-26 13:56:04 +0200
commitabad2ebad9c78e3978343aa0fc572a87dbf9fa78 (patch)
tree1afccd19ba25874af6069eacf1c81075631d904a
parent300c0fd9c956984d3a4d5275de4483a5e280d7db (diff)
update rust code
-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")
}