Added the ability to get tags from the database.
Also fixed the way the example was compiling so it didn't act weird on other features.
This commit is contained in:
@ -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"] }
|
||||
|
||||
|
||||
|
||||
|
||||
@ -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<P>(filename: P) -> std::path::PathBuf
|
||||
where P: AsRef<std::path::Path>
|
||||
{
|
||||
@ -82,6 +86,7 @@ fn create_temp_file<P>(filename: P) -> std::path::PathBuf
|
||||
path
|
||||
}
|
||||
|
||||
#[cfg(feature = "publisher")]
|
||||
fn cleanup_temp_file<P>(path: P)
|
||||
where P: AsRef<std::path::Path>
|
||||
{
|
||||
@ -102,6 +107,7 @@ fn cleanup_temp_file<P>(path: P)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "publisher")]
|
||||
fn write_to_file<P>(tavern: Tavern, config_file: P) -> Result<(), Box<dyn std::error::Error>>
|
||||
where P: AsRef<std::path::Path>
|
||||
{
|
||||
@ -112,6 +118,7 @@ fn write_to_file<P>(tavern: Tavern, config_file: P) -> Result<(), Box<dyn std::e
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "publisher")]
|
||||
fn read_from_file<P>(config_file: P) -> Tavern
|
||||
where P: AsRef<std::path::Path>
|
||||
{
|
||||
@ -124,6 +131,7 @@ fn read_from_file<P>(config_file: P) -> Tavern
|
||||
}
|
||||
|
||||
|
||||
#[cfg(feature = "publisher")]
|
||||
async fn create_database() -> Result<(), Box<dyn std::error::Error>>
|
||||
{
|
||||
// First we need to generate a TOML file to work with.
|
||||
@ -148,6 +156,7 @@ async fn create_database() -> Result<(), Box<dyn std::error::Error>>
|
||||
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()
|
||||
{
|
||||
}
|
||||
|
||||
@ -274,6 +274,27 @@ impl Database
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(any(not(feature = "publisher"), feature = "tester"))]
|
||||
pub async fn get_all_tags(&self) -> Result<Vec<String>>
|
||||
{
|
||||
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<Vec<Lore>>
|
||||
|
||||
Reference in New Issue
Block a user