From 0972fa6eab8c9111311f082ba8abfdc6b4a40945 Mon Sep 17 00:00:00 2001 From: nil Date: Wed, 2 Oct 2024 17:48:56 +0200 Subject: commit changes --- .gitignore | 5 +++ .ignore | 1 + Cargo.toml | 17 ++++++++ N | 2 + env_example | 1 + python/.gitignore | 1 - python/database.py | 58 -------------------------- python/main.py | 4 -- python/routes.py | 33 --------------- rust/.gitignore | 5 --- rust/.ignore | 1 - rust/Cargo.toml | 17 -------- rust/N | 2 - rust/env_example | 1 - rust/scripts/create_db.sh | 11 ----- rust/scripts/create_db.sql | 41 ------------------ rust/scripts/create_user.sql | 3 -- rust/scripts/populate.sh | 13 ------ rust/scripts/populate/.gitignore | 3 -- rust/scripts/populate/albums.py | 38 ----------------- rust/scripts/populate/api.py | 21 ---------- rust/scripts/populate/create_db.sql | 39 ----------------- rust/scripts/populate/database.py | 83 ------------------------------------- rust/scripts/populate/main.py | 46 -------------------- rust/scripts/populate/parser.py | 83 ------------------------------------- rust/scripts/populate/structures.py | 13 ------ rust/src/main.rs | 35 ---------------- rust/src/routes.rs | 1 - rust/src/routes/hello.rs | 11 ----- rust/src/structs.rs | 35 ---------------- scripts/create_db.sh | 27 ++++++++++++ scripts/create_db.sql | 41 ++++++++++++++++++ scripts/create_user.sql | 3 ++ scripts/populate.sh | 13 ++++++ scripts/populate/.gitignore | 3 ++ scripts/populate/albums.py | 38 +++++++++++++++++ scripts/populate/api.py | 21 ++++++++++ scripts/populate/create_db.sql | 39 +++++++++++++++++ scripts/populate/database.py | 83 +++++++++++++++++++++++++++++++++++++ scripts/populate/main.py | 46 ++++++++++++++++++++ scripts/populate/parser.py | 83 +++++++++++++++++++++++++++++++++++++ scripts/populate/structures.py | 13 ++++++ src/main.rs | 35 ++++++++++++++++ src/routes.rs | 0 src/routes/hello.rs | 11 +++++ src/structs.rs | 35 ++++++++++++++++ 46 files changed, 517 insertions(+), 598 deletions(-) create mode 100644 .gitignore create mode 100644 .ignore create mode 100644 Cargo.toml create mode 100644 N create mode 100644 env_example delete mode 100644 python/.gitignore delete mode 100644 python/database.py delete mode 100644 python/main.py delete mode 100644 python/routes.py delete mode 100644 rust/.gitignore delete mode 100644 rust/.ignore delete mode 100644 rust/Cargo.toml delete mode 100644 rust/N delete mode 100644 rust/env_example delete mode 100644 rust/scripts/create_db.sh delete mode 100644 rust/scripts/create_db.sql delete mode 100644 rust/scripts/create_user.sql delete mode 100644 rust/scripts/populate.sh delete mode 100644 rust/scripts/populate/.gitignore delete mode 100644 rust/scripts/populate/albums.py delete mode 100644 rust/scripts/populate/api.py delete mode 100644 rust/scripts/populate/create_db.sql delete mode 100644 rust/scripts/populate/database.py delete mode 100644 rust/scripts/populate/main.py delete mode 100644 rust/scripts/populate/parser.py delete mode 100644 rust/scripts/populate/structures.py delete mode 100644 rust/src/main.rs delete mode 100644 rust/src/routes.rs delete mode 100644 rust/src/routes/hello.rs delete mode 100644 rust/src/structs.rs create mode 100644 scripts/create_db.sh create mode 100644 scripts/create_db.sql create mode 100644 scripts/create_user.sql create mode 100644 scripts/populate.sh create mode 100644 scripts/populate/.gitignore create mode 100644 scripts/populate/albums.py create mode 100644 scripts/populate/api.py create mode 100644 scripts/populate/create_db.sql create mode 100644 scripts/populate/database.py create mode 100644 scripts/populate/main.py create mode 100644 scripts/populate/parser.py create mode 100644 scripts/populate/structures.py create mode 100644 src/main.rs create mode 100644 src/routes.rs create mode 100644 src/routes/hello.rs create mode 100644 src/structs.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9adab75 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +lock/ +target/ +Cargo.lock +**/*.rs.bk +.env diff --git a/.ignore b/.ignore new file mode 100644 index 0000000..2ce903e --- /dev/null +++ b/.ignore @@ -0,0 +1 @@ +scripts/populate/ diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..b4a8000 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "ver1" +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" + +[package.metadata.scripts] +db_create = "bash ./scripts/create_db.sh" +db_populate = "bash ./scripts/populate.sh" +# db_start = "sudo docker start sqlx" +# db_start = "sudo docker stop sqlx" +# db_remove = "sudo docker rm sqlx" diff --git a/N b/N new file mode 100644 index 0000000..a755b9a --- /dev/null +++ b/N @@ -0,0 +1,2 @@ +cargo install cargo-run-script +cargo-run-script db-create diff --git a/env_example b/env_example new file mode 100644 index 0000000..607b7cc --- /dev/null +++ b/env_example @@ -0,0 +1 @@ +DATABASE_URL="mysql://balalaika_user:password@127.0.0.1:3306/balalaika" diff --git a/python/.gitignore b/python/.gitignore deleted file mode 100644 index c18dd8d..0000000 --- a/python/.gitignore +++ /dev/null @@ -1 +0,0 @@ -__pycache__/ diff --git a/python/database.py b/python/database.py deleted file mode 100644 index 06f5d61..0000000 --- a/python/database.py +++ /dev/null @@ -1,58 +0,0 @@ -import mysql.connector - - -connector = mysql.connector.connect( - host="localhost", - user="root", - database="balalaika", -) - -cursor = connector.cursor() - - -def get_song(id, name): - if id is None: - id = "%" - - if name is None: - name = "%" - - cursor.execute( - """ - select * from song - where id like %(id)s - and name like %(name)s; - """, - { - 'id': id, - 'name': name, - } - ) - - return cursor.fetchall() - - -def get_filtered_songs(song, album, artist): - if artist is None: - artist = "%" - - if album is None: - album = "%" - - cursor.execute( - """ - select song.name, album.name, artist.name - from song - inner join album on song.album_id=album.id - inner join artist on album.artist_id=artist.id - where artist.name like %(artist)s - and album.name like %(album)s; - """, - { - 'artist': artist, - 'album': album, - 'song': song, - } - ) - - return cursor.fetchall() diff --git a/python/main.py b/python/main.py deleted file mode 100644 index d7eb1b6..0000000 --- a/python/main.py +++ /dev/null @@ -1,4 +0,0 @@ -import routes - - -routes.app.run() diff --git a/python/routes.py b/python/routes.py deleted file mode 100644 index 9567318..0000000 --- a/python/routes.py +++ /dev/null @@ -1,33 +0,0 @@ -from flask import Flask, jsonify, request -import database - - -app = Flask(__name__) - - -def run(): - app.run() - - -@app.route("/", methods=['GET']) -def hello_world(): - return "not here" - - -@app.route("/song", methods=['GET']) -def get_song(): - id = request.args.get('id') - name = request.args.get('name') - return jsonify(database.get_song(id=id, name=name)) - - -@app.route("/songs", methods=['GET']) -def get_filtered_songs(): - song = request.args.get('song') - album = request.args.get('album') - artist = request.args.get('artist') - return jsonify( - database.get_filtered_songs( - song=song, album=album, artist=artist - ) - ) diff --git a/rust/.gitignore b/rust/.gitignore deleted file mode 100644 index 9adab75..0000000 --- a/rust/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -lock/ -target/ -Cargo.lock -**/*.rs.bk -.env diff --git a/rust/.ignore b/rust/.ignore deleted file mode 100644 index 0b68341..0000000 --- a/rust/.ignore +++ /dev/null @@ -1 +0,0 @@ -# scripts/populate/ diff --git a/rust/Cargo.toml b/rust/Cargo.toml deleted file mode 100644 index b4a8000..0000000 --- a/rust/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "ver1" -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" - -[package.metadata.scripts] -db_create = "bash ./scripts/create_db.sh" -db_populate = "bash ./scripts/populate.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 deleted file mode 100644 index a755b9a..0000000 --- a/rust/N +++ /dev/null @@ -1,2 +0,0 @@ -cargo install cargo-run-script -cargo-run-script db-create diff --git a/rust/env_example b/rust/env_example deleted file mode 100644 index 607b7cc..0000000 --- a/rust/env_example +++ /dev/null @@ -1 +0,0 @@ -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 deleted file mode 100644 index 4e6ebc1..0000000 --- a/rust/scripts/create_db.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -echo "choose a password for the database:" -read input -echo "creating database..." -sudo mariadb -u root < std::io::Result<()> { - 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)) - .service(routes::hello::hello_actix) - }) - .bind(("127.0.0.1", 8000))? - .run() - .await -} - -async fn root() -> String { - String::from("Server is up and running") -} diff --git a/rust/src/routes.rs b/rust/src/routes.rs deleted file mode 100644 index 8cb6ff0..0000000 --- a/rust/src/routes.rs +++ /dev/null @@ -1 +0,0 @@ -mod hello; diff --git a/rust/src/routes/hello.rs b/rust/src/routes/hello.rs deleted file mode 100644 index c356081..0000000 --- a/rust/src/routes/hello.rs +++ /dev/null @@ -1,11 +0,0 @@ -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/rust/src/structs.rs b/rust/src/structs.rs deleted file mode 100644 index 7535bb4..0000000 --- a/rust/src/structs.rs +++ /dev/null @@ -1,35 +0,0 @@ -#[allow(dead_code)] -struct Song { - //song variables - id: i32, - title: String, - lyrics: String, - - //album variables - album_id: i32, - genres: Vec, - album_cover: String, - - //artist variables - artist_id: i32, - artist_name: String, -} - -#[allow(dead_code)] -struct Album { - id: i32, - title: String, - genres: Vec, - cover: String, - songs: Vec, -} - -#[allow(dead_code)] -struct Artist { - id: i32, - name: String, - genres: Vec, - albums: Vec, -} - -// lepht anonym diff --git a/scripts/create_db.sh b/scripts/create_db.sh new file mode 100644 index 0000000..c0e759c --- /dev/null +++ b/scripts/create_db.sh @@ -0,0 +1,27 @@ +#!/bin/bash +echo "choose a password for the database:" +read input +echo "use xampp's version of mariadb? [y/n]" +read answer + +if [[ $answer == 'y' ]] then + mariadb="/opt/lampp/bin/mariadb" +else + mariadb="mariadb" +fi + +echo "use sudo? [y/n]" +read answer + +if [[ $answer == 'y' ]] then + sudo="sudo" +fi + +echo "creating database..." +$sudo $mariadb -u root < std::io::Result<()> { + 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)) + .service(routes::hello::hello_actix) + }) + .bind(("127.0.0.1", 8000))? + .run() + .await +} + +async fn root() -> String { + String::from("Server is up and running") +} diff --git a/src/routes.rs b/src/routes.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/routes/hello.rs b/src/routes/hello.rs new file mode 100644 index 0000000..c356081 --- /dev/null +++ b/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/src/structs.rs b/src/structs.rs new file mode 100644 index 0000000..7535bb4 --- /dev/null +++ b/src/structs.rs @@ -0,0 +1,35 @@ +#[allow(dead_code)] +struct Song { + //song variables + id: i32, + title: String, + lyrics: String, + + //album variables + album_id: i32, + genres: Vec, + album_cover: String, + + //artist variables + artist_id: i32, + artist_name: String, +} + +#[allow(dead_code)] +struct Album { + id: i32, + title: String, + genres: Vec, + cover: String, + songs: Vec, +} + +#[allow(dead_code)] +struct Artist { + id: i32, + name: String, + genres: Vec, + albums: Vec, +} + +// lepht anonym -- cgit v1.2.3