From db58cb58b5d5612ec2aa347d0f8531b26ab2e7f3 Mon Sep 17 00:00:00 2001 From: niliara-edu Date: Fri, 27 Sep 2024 14:04:23 +0200 Subject: upload changes --- rust/.gitignore | 1 + rust/Cargo.toml | 8 +++++++- rust/N | 2 ++ rust/env_example | 1 + rust/scripts/create_db.sh | 10 ++++++++++ rust/scripts/create_db.sql | 41 +++++++++++++++++++++++++++++++++++++++++ rust/scripts/create_user.sql | 1 + rust/src/main.rs | 4 ++-- rust/src/routes.rs | 1 + rust/src/routes/hello.rs | 11 +++++++++++ scrap/database.py | 11 ++++++++++- 11 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 rust/N create mode 100644 rust/env_example create mode 100644 rust/scripts/create_db.sh create mode 100644 rust/scripts/create_db.sql create mode 100644 rust/scripts/create_user.sql create mode 100644 rust/src/routes.rs create mode 100644 rust/src/routes/hello.rs diff --git a/rust/.gitignore b/rust/.gitignore index 523b2b0..9adab75 100644 --- a/rust/.gitignore +++ b/rust/.gitignore @@ -2,3 +2,4 @@ lock/ target/ Cargo.lock **/*.rs.bk +.env diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 6fdfa00..bc8db03 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -5,6 +5,12 @@ edition = "2021" [dependencies] actix-web = { version = "4.9.0"} -sqlx = { version = "0.8.2", features = ["mysql", "macros" , "runtime-tokio"] } +sqlx = { version = "0.8.2", features = ["mysql", "macros", "runtime-tokio"] } serde = { version = "1.0.210", features = ["derive"] } tokio = "1.40.0" + +[package.metadata.scripts] +db_create = "bash ./scripts/create_db.sh" +# db_start = "sudo docker start sqlx" +# db_start = "sudo docker stop sqlx" +# db_remove = "sudo docker rm sqlx" diff --git a/rust/N b/rust/N new file mode 100644 index 0000000..a755b9a --- /dev/null +++ b/rust/N @@ -0,0 +1,2 @@ +cargo install cargo-run-script +cargo-run-script db-create diff --git a/rust/env_example b/rust/env_example new file mode 100644 index 0000000..607b7cc --- /dev/null +++ b/rust/env_example @@ -0,0 +1 @@ +DATABASE_URL="mysql://balalaika_user:password@127.0.0.1:3306/balalaika" diff --git a/rust/scripts/create_db.sh b/rust/scripts/create_db.sh new file mode 100644 index 0000000..cddcdd9 --- /dev/null +++ b/rust/scripts/create_db.sh @@ -0,0 +1,10 @@ +#!/bin/bash +echo "choose a password for the database: 'input;" +read input +echo $(pwd) +echo "creating database..." +sudo mariadb -u root < 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) @@ -24,6 +23,7 @@ async fn main() -> std::io::Result<()> { App::new() .app_data(web::Data::new(app_state.clone())) .route("/", web::get().to(root)) + .service(routes::hello::hello_actix) }) .bind(("127.0.0.1", 8000))? .run() diff --git a/rust/src/routes.rs b/rust/src/routes.rs new file mode 100644 index 0000000..8cb6ff0 --- /dev/null +++ b/rust/src/routes.rs @@ -0,0 +1 @@ +mod hello; diff --git a/rust/src/routes/hello.rs b/rust/src/routes/hello.rs new file mode 100644 index 0000000..c356081 --- /dev/null +++ b/rust/src/routes/hello.rs @@ -0,0 +1,11 @@ +use crate::AppState; +use actix_web::{get, web, HttpResponse}; +use serde::Deserialize; + +#[get("/hello")] +pub async fn hello_actix(app_state: web::Data) -> HttpResponse { + struct Song { + } + + return HttpResponse::Ok().json(databases); +} diff --git a/scrap/database.py b/scrap/database.py index d7c0e0c..2319812 100644 --- a/scrap/database.py +++ b/scrap/database.py @@ -1,14 +1,23 @@ import mysql.connector +import getpass + + +def get_database_password(): + return getpass.getpass("Insert database password: ") + connector = mysql.connector.connect( host="localhost", - user="root", + user="balalaika_user", + password=get_database_password(), database="balalaika", ) cursor = connector.cursor() + + def process_albums(album_list): [process_album(album, album_id) for album_id, album in enumerate(album_list, 1)] -- cgit v1.2.3