diff --git a/tavern/Cargo.toml b/tavern/Cargo.toml index e2418a9..51e6883 100644 --- a/tavern/Cargo.toml +++ b/tavern/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tavern" -version = "0.2.5" +version = "0.2.6" edition = "2024" description = "A blogging system that will allow you to write your blog in Markdown and then display it in HTML using Dioxus." repository = "/CyberMages/tavern" @@ -18,7 +18,7 @@ sqlx = { version = "0.8.6", features = ["sqlite", "chrono", "runtime-tokio"], op toml = "0.9.5" [dev-dependencies] -tokio = { version = "1", features = ["full"] } +tokio = { version = "1", features = ["rt-multi-thread", "macros"] } diff --git a/tavern/examples/generate_database.rs b/tavern/examples/generate_database.rs index 8a451e0..f96eb99 100644 --- a/tavern/examples/generate_database.rs +++ b/tavern/examples/generate_database.rs @@ -1,13 +1,16 @@ -#![cfg(feature = "publisher")] - +#[cfg(feature = "publisher")] use chrono::NaiveDate; +#[cfg(feature = "publisher")] use tavern::{Adventurer, Legend, Lore, Story, Tale, Tavern}; + +#[cfg(feature = "publisher")] use tavern::Database; /// This will generate a tavern that we can create a Toml file from. +#[cfg(feature = "publisher")] fn generate_tavern() -> Tavern { let legend: Legend = Legend @@ -73,6 +76,7 @@ fn generate_tavern() -> Tavern } +#[cfg(feature = "publisher")] fn create_temp_file

(filename: P) -> std::path::PathBuf where P: AsRef { @@ -82,6 +86,7 @@ fn create_temp_file

(filename: P) -> std::path::PathBuf path } +#[cfg(feature = "publisher")] fn cleanup_temp_file

(path: P) where P: AsRef { @@ -102,6 +107,7 @@ fn cleanup_temp_file

(path: P) } } +#[cfg(feature = "publisher")] fn write_to_file

(tavern: Tavern, config_file: P) -> Result<(), Box> where P: AsRef { @@ -112,6 +118,7 @@ fn write_to_file

(tavern: Tavern, config_file: P) -> Result<(), Box(config_file: P) -> Tavern where P: AsRef { @@ -124,6 +131,7 @@ fn read_from_file

(config_file: P) -> Tavern } +#[cfg(feature = "publisher")] async fn create_database() -> Result<(), Box> { // First we need to generate a TOML file to work with. @@ -148,6 +156,7 @@ async fn create_database() -> Result<(), Box> Ok(()) } +#[cfg(feature = "publisher")] #[tokio::main] pub async fn main() { @@ -157,3 +166,10 @@ pub async fn main() Err(e) => { eprintln!("Error: {}", e); } } } + + +#[cfg(not(feature = "publisher"))] +#[tokio::main] +pub async fn main() +{ +} diff --git a/tavern/src/database.rs b/tavern/src/database.rs index 662e474..b3ecff5 100644 --- a/tavern/src/database.rs +++ b/tavern/src/database.rs @@ -274,6 +274,27 @@ impl Database Ok(()) } + #[cfg(any(not(feature = "publisher"), feature = "tester"))] + pub async fn get_all_tags(&self) -> Result> + { + let mut tx = self.pool.begin().await?; + + let rows = sqlx::query!( + "SELECT name FROM tags ORDER BY name ASC" + ) + .fetch_all(&mut *tx) + .await?; + + tx.commit().await?; + + let tags = rows + .into_iter() + .filter_map(|row| Some(row.name)) + .collect(); + + Ok(tags) + } + #[cfg(any(not(feature = "publisher"), feature = "tester"))] pub async fn get_tales_summary(&self, categories: &[String]) -> Result>