From 7c65b526d9c1e3662d48202f260b3d38e858afc6 Mon Sep 17 00:00:00 2001 From: Mara Schulke Date: Tue, 13 Feb 2024 18:19:31 +0100 Subject: [PATCH] Repair the main branch (#16) * Fix the features * Make CI build all features * Update ci * Fix fmt * Undo cargo fmt changes * Specifcally test against pg * Fix host * Fix the book * Repair the book * Remove keeper tests from the book * Fix examples * Add the default * Repair atmosphere --- Cargo.toml | 8 +++++--- atmosphere-core/src/lib.rs | 14 +------------- atmosphere-macros/Cargo.toml | 6 ++++++ examples/blog/main.rs | 5 ++++- examples/forest/main.rs | 5 ++++- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 44b5648..28d150a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,9 +41,9 @@ sqlx.workspace = true [features] default = [] -mysql = ["atmosphere-core/mysql"] -postgres = ["atmosphere-core/postgres"] -sqlite = ["atmosphere-core/sqlite"] +mysql = ["atmosphere-core/mysql", "atmosphere-macros/mysql"] +postgres = ["atmosphere-core/postgres", "atmosphere-macros/postgres"] +sqlite = ["atmosphere-core/sqlite", "atmosphere-macros/sqlite"] [dev-dependencies] sqlx = { version = "0.7", features = ["runtime-tokio-rustls", "any", "sqlite", "mysql", "postgres"] } @@ -53,10 +53,12 @@ tokio-test = "0" [[example]] name = "forest" path = "examples/forest/main.rs" +required-features = ["sqlite"] [[example]] name = "blog" path = "examples/blog/main.rs" +required-features = ["sqlite"] [[test]] name = "integration" diff --git a/atmosphere-core/src/lib.rs b/atmosphere-core/src/lib.rs index a460749..f0bcd3c 100644 --- a/atmosphere-core/src/lib.rs +++ b/atmosphere-core/src/lib.rs @@ -72,14 +72,6 @@ pub mod driver { ))] compile_error!("only one database driver can be set – please use multiple binaries using different atmosphere features if you need more than one database"); - #[cfg(all( - not(feature = "mysql"), - not(feature = "postgres"), - not(feature = "sqlite") - ))] - /// Atmosphere Database Driver - pub type Driver = sqlx::Any; - #[cfg(all(feature = "postgres", not(any(feature = "mysql", feature = "sqlite"))))] /// Atmosphere Database Driver pub type Driver = sqlx::Postgres; @@ -104,11 +96,7 @@ pub mod driver { /// Atmosphere Database Pool pub type Pool = sqlx::SqlitePool; - #[cfg(all( - not(feature = "postgres"), - not(feature = "mysql"), - not(feature = "sqlite") - ))] + #[cfg(not(any(feature = "postgres", feature = "mysql", feature = "sqlite")))] compile_error!( "you must chose a atmosphere database driver (available: postgres, mysql, sqlite)" ); diff --git a/atmosphere-macros/Cargo.toml b/atmosphere-macros/Cargo.toml index 9bc60c5..02ea798 100644 --- a/atmosphere-macros/Cargo.toml +++ b/atmosphere-macros/Cargo.toml @@ -18,5 +18,11 @@ syn = { version = "2.0.39", default-features = false, features = ["parsing", "pr quote = { version = "1.0.14", default-features = false } lazy_static = "1.4.0" +[features] +default = [] +mysql = ["atmosphere-core/mysql"] +postgres = ["atmosphere-core/postgres"] +sqlite = ["atmosphere-core/sqlite"] + [dev-dependencies] chrono = "0.4.31" diff --git a/examples/blog/main.rs b/examples/blog/main.rs index f74b6f8..8fe1847 100644 --- a/examples/blog/main.rs +++ b/examples/blog/main.rs @@ -32,7 +32,10 @@ struct Post { #[tokio::main] async fn main() -> atmosphere::Result<()> { - let pool = Pool::connect(&std::env::var("DATABASE_URL").unwrap()) + let pool = Pool::connect(":memory:").await.unwrap(); + + sqlx::migrate!("examples/blog/migrations") + .run(&pool) .await .unwrap(); diff --git a/examples/forest/main.rs b/examples/forest/main.rs index 9f672b1..dd403de 100644 --- a/examples/forest/main.rs +++ b/examples/forest/main.rs @@ -26,7 +26,10 @@ struct Tree { #[tokio::main] async fn main() -> atmosphere::Result<()> { - let pool = Pool::connect(&std::env::var("DATABASE_URL").unwrap()) + let pool = Pool::connect(":memory:").await.unwrap(); + + sqlx::migrate!("examples/forest/migrations") + .run(&pool) .await .unwrap();