From 9524d95dd7112dc598fec4ec12e88ad13a210fc9 Mon Sep 17 00:00:00 2001 From: Chrislearn Young Date: Tue, 20 Sep 2022 17:44:30 +0800 Subject: [PATCH] sea-orm update for ci --- examples/{seaorm => db-sea-orm}/Cargo.toml | 11 ++++------- examples/{seaorm => db-sea-orm}/README.md | 2 +- examples/{seaorm => db-sea-orm}/Screenshot.png | Bin .../src/lib.rs => db-sea-orm/src/entity/mod.rs} | 0 .../entity/src => db-sea-orm/src/entity}/post.rs | 0 examples/{seaorm => db-sea-orm}/src/main.rs | 11 ++++++----- .../src}/migration/README.md | 0 .../m20220120_000001_create_post_table.rs | 0 .../src => db-sea-orm/src/migration}/main.rs | 0 .../lib.rs => db-sea-orm/src/migration/mod.rs} | 0 .../static/css/normalize.css | 0 .../static/css/skeleton.css | 0 .../{seaorm => db-sea-orm}/static/css/style.css | 0 .../static/images/favicon.png | Bin .../templates/edit.html.tera | 0 .../templates/error/404.html.tera | 0 .../templates/index.html.tera | 0 .../templates/layout.html.tera | 0 .../templates/new.html.tera | 0 examples/seaorm/.env | 4 ---- examples/seaorm/.gitignore | 3 --- examples/seaorm/entity/Cargo.toml | 14 -------------- examples/seaorm/migration/Cargo.toml | 13 ------------- 23 files changed, 11 insertions(+), 47 deletions(-) rename examples/{seaorm => db-sea-orm}/Cargo.toml (68%) rename examples/{seaorm => db-sea-orm}/README.md (87%) rename examples/{seaorm => db-sea-orm}/Screenshot.png (100%) rename examples/{seaorm/entity/src/lib.rs => db-sea-orm/src/entity/mod.rs} (100%) rename examples/{seaorm/entity/src => db-sea-orm/src/entity}/post.rs (100%) rename examples/{seaorm => db-sea-orm}/src/main.rs (95%) rename examples/{seaorm => db-sea-orm/src}/migration/README.md (100%) rename examples/{seaorm/migration/src => db-sea-orm/src/migration}/m20220120_000001_create_post_table.rs (100%) rename examples/{seaorm/migration/src => db-sea-orm/src/migration}/main.rs (100%) rename examples/{seaorm/migration/src/lib.rs => db-sea-orm/src/migration/mod.rs} (100%) rename examples/{seaorm => db-sea-orm}/static/css/normalize.css (100%) rename examples/{seaorm => db-sea-orm}/static/css/skeleton.css (100%) rename examples/{seaorm => db-sea-orm}/static/css/style.css (100%) rename examples/{seaorm => db-sea-orm}/static/images/favicon.png (100%) rename examples/{seaorm => db-sea-orm}/templates/edit.html.tera (100%) rename examples/{seaorm => db-sea-orm}/templates/error/404.html.tera (100%) rename examples/{seaorm => db-sea-orm}/templates/index.html.tera (100%) rename examples/{seaorm => db-sea-orm}/templates/layout.html.tera (100%) rename examples/{seaorm => db-sea-orm}/templates/new.html.tera (100%) delete mode 100644 examples/seaorm/.env delete mode 100644 examples/seaorm/.gitignore delete mode 100644 examples/seaorm/entity/Cargo.toml delete mode 100644 examples/seaorm/migration/Cargo.toml diff --git a/examples/seaorm/Cargo.toml b/examples/db-sea-orm/Cargo.toml similarity index 68% rename from examples/seaorm/Cargo.toml rename to examples/db-sea-orm/Cargo.toml index d77123221..13d2e0cfc 100644 --- a/examples/seaorm/Cargo.toml +++ b/examples/db-sea-orm/Cargo.toml @@ -1,11 +1,8 @@ [package] -name = "sea-orm-salvo-example" +name = "example-db-sea-orm" version = "0.1.0" edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[workspace] -members = [".", "entity", "migration"] +publish = false [dependencies] tokio = { version = "1.21.1", features = ["macros", "rt-multi-thread"] } @@ -15,8 +12,6 @@ tracing-subscriber = { version = "0.3.15", features = ["env-filter"] } serde = { version = "1.0.144", features = ["derive"] } tera = "1.17.1" dotenv = "0.15" -entity = { path = "entity" } -migration = { path = "migration" } sea-orm = { version = "0.9.2", features = [ "debug-print", "runtime-tokio-native-tls", @@ -24,3 +19,5 @@ sea-orm = { version = "0.9.2", features = [ # "sqlx-postgres", # "sqlx-mysql", ] } +async-std = { version = "^1", features = ["attributes", "tokio1"] } +sea-orm-migration = "0.9.2" diff --git a/examples/seaorm/README.md b/examples/db-sea-orm/README.md similarity index 87% rename from examples/seaorm/README.md rename to examples/db-sea-orm/README.md index 7c5e8b738..8cd8b3f67 100644 --- a/examples/seaorm/README.md +++ b/examples/db-sea-orm/README.md @@ -10,4 +10,4 @@ 3. Execute `cargo run` to start the server -4. Visit [localhost:8000](http://localhost:8000) in browser after seeing the `server started` line +4. Visit [localhost:7878](http://localhost:7878) in browser after seeing the `server started` line diff --git a/examples/seaorm/Screenshot.png b/examples/db-sea-orm/Screenshot.png similarity index 100% rename from examples/seaorm/Screenshot.png rename to examples/db-sea-orm/Screenshot.png diff --git a/examples/seaorm/entity/src/lib.rs b/examples/db-sea-orm/src/entity/mod.rs similarity index 100% rename from examples/seaorm/entity/src/lib.rs rename to examples/db-sea-orm/src/entity/mod.rs diff --git a/examples/seaorm/entity/src/post.rs b/examples/db-sea-orm/src/entity/post.rs similarity index 100% rename from examples/seaorm/entity/src/post.rs rename to examples/db-sea-orm/src/entity/post.rs diff --git a/examples/seaorm/src/main.rs b/examples/db-sea-orm/src/main.rs similarity index 95% rename from examples/seaorm/src/main.rs rename to examples/db-sea-orm/src/main.rs index c815bdd1a..ee89f60a6 100644 --- a/examples/seaorm/src/main.rs +++ b/examples/db-sea-orm/src/main.rs @@ -9,6 +9,9 @@ use salvo::writer::Text; use sea_orm::{entity::*, query::*, DatabaseConnection}; use tera::Tera; +mod entity; +mod migration; + const DEFAULT_POSTS_PER_PAGE: u64 = 5; type Result = std::result::Result; @@ -156,15 +159,13 @@ async fn main() { std::env::set_var("RUST_LOG", "debug"); tracing_subscriber::fmt::init(); - // get env vars - dotenv::dotenv().ok(); - let db_url = env::var("DATABASE_URL").expect("DATABASE_URL is not set in .env file"); + let db_url = "sqlite::memory:"; let host = env::var("HOST").unwrap_or("0.0.0.0".to_owned()); - let port = env::var("PORT").unwrap_or("8080".to_owned()); + let port = env::var("PORT").unwrap_or("7878".to_owned()); let server_url = format!("{}:{}", host, port); // create post table if not exists - let conn = sea_orm::Database::connect(&db_url).await.unwrap(); + let conn = sea_orm::Database::connect(db_url).await.unwrap(); Migrator::up(&conn, None).await.unwrap(); let templates = Tera::new(concat!(env!("CARGO_MANIFEST_DIR"), "/templates/**/*")).unwrap(); let state = AppState { templates, conn }; diff --git a/examples/seaorm/migration/README.md b/examples/db-sea-orm/src/migration/README.md similarity index 100% rename from examples/seaorm/migration/README.md rename to examples/db-sea-orm/src/migration/README.md diff --git a/examples/seaorm/migration/src/m20220120_000001_create_post_table.rs b/examples/db-sea-orm/src/migration/m20220120_000001_create_post_table.rs similarity index 100% rename from examples/seaorm/migration/src/m20220120_000001_create_post_table.rs rename to examples/db-sea-orm/src/migration/m20220120_000001_create_post_table.rs diff --git a/examples/seaorm/migration/src/main.rs b/examples/db-sea-orm/src/migration/main.rs similarity index 100% rename from examples/seaorm/migration/src/main.rs rename to examples/db-sea-orm/src/migration/main.rs diff --git a/examples/seaorm/migration/src/lib.rs b/examples/db-sea-orm/src/migration/mod.rs similarity index 100% rename from examples/seaorm/migration/src/lib.rs rename to examples/db-sea-orm/src/migration/mod.rs diff --git a/examples/seaorm/static/css/normalize.css b/examples/db-sea-orm/static/css/normalize.css similarity index 100% rename from examples/seaorm/static/css/normalize.css rename to examples/db-sea-orm/static/css/normalize.css diff --git a/examples/seaorm/static/css/skeleton.css b/examples/db-sea-orm/static/css/skeleton.css similarity index 100% rename from examples/seaorm/static/css/skeleton.css rename to examples/db-sea-orm/static/css/skeleton.css diff --git a/examples/seaorm/static/css/style.css b/examples/db-sea-orm/static/css/style.css similarity index 100% rename from examples/seaorm/static/css/style.css rename to examples/db-sea-orm/static/css/style.css diff --git a/examples/seaorm/static/images/favicon.png b/examples/db-sea-orm/static/images/favicon.png similarity index 100% rename from examples/seaorm/static/images/favicon.png rename to examples/db-sea-orm/static/images/favicon.png diff --git a/examples/seaorm/templates/edit.html.tera b/examples/db-sea-orm/templates/edit.html.tera similarity index 100% rename from examples/seaorm/templates/edit.html.tera rename to examples/db-sea-orm/templates/edit.html.tera diff --git a/examples/seaorm/templates/error/404.html.tera b/examples/db-sea-orm/templates/error/404.html.tera similarity index 100% rename from examples/seaorm/templates/error/404.html.tera rename to examples/db-sea-orm/templates/error/404.html.tera diff --git a/examples/seaorm/templates/index.html.tera b/examples/db-sea-orm/templates/index.html.tera similarity index 100% rename from examples/seaorm/templates/index.html.tera rename to examples/db-sea-orm/templates/index.html.tera diff --git a/examples/seaorm/templates/layout.html.tera b/examples/db-sea-orm/templates/layout.html.tera similarity index 100% rename from examples/seaorm/templates/layout.html.tera rename to examples/db-sea-orm/templates/layout.html.tera diff --git a/examples/seaorm/templates/new.html.tera b/examples/db-sea-orm/templates/new.html.tera similarity index 100% rename from examples/seaorm/templates/new.html.tera rename to examples/db-sea-orm/templates/new.html.tera diff --git a/examples/seaorm/.env b/examples/seaorm/.env deleted file mode 100644 index acd83c0e1..000000000 --- a/examples/seaorm/.env +++ /dev/null @@ -1,4 +0,0 @@ -HOST=127.0.0.1 -PORT=8000 -#DATABASE_URL="mysql://root:@localhost/poem_example" -DATABASE_URL="sqlite::memory:" diff --git a/examples/seaorm/.gitignore b/examples/seaorm/.gitignore deleted file mode 100644 index 4e0d9c4c5..000000000 --- a/examples/seaorm/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -.idea -*.exe -Cargo.lock diff --git a/examples/seaorm/entity/Cargo.toml b/examples/seaorm/entity/Cargo.toml deleted file mode 100644 index 9003cf837..000000000 --- a/examples/seaorm/entity/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "entity" -version = "0.1.0" -edition = "2021" -publish = false - -[lib] -name = "entity" -path = "src/lib.rs" - -[dependencies] -serde = { version = "1", features = ["derive"] } -sea-orm = "0.9.2" -sea-orm-migration = "0.9.2" diff --git a/examples/seaorm/migration/Cargo.toml b/examples/seaorm/migration/Cargo.toml deleted file mode 100644 index 326160b79..000000000 --- a/examples/seaorm/migration/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "migration" -version = "0.1.0" -edition = "2021" -publish = false - -[lib] -name = "migration" -path = "src/lib.rs" - -[dependencies] -async-std = { version = "^1", features = ["attributes", "tokio1"] } -sea-orm-migration = "0.9.2"