atomic_lib 0.41.0-beta.2

Library for creating, storing, querying, validating and converting Atomic Data.
Documentation
use atomic_lib::errors::AtomicResult;
use atomic_lib::{storelike::Query, Store, Storelike};

#[tokio::main(flavor = "current_thread")]
async fn main() -> AtomicResult<()> {
    // Initialize a new store
    let store = Store::init().await?;
    // Populate it with some default data
    store.populate().await?;

    // Create a query for all resources that are instances of the Class class
    let mut query = Query::new_class("https://atomicdata.dev/classes/Class");
    // Include resources from other servers as well
    query.include_external = true;

    // Execute the query
    let result = store.query(&query).await?;

    println!("Found {} instances of Class:", result.subjects.len());

    // Iterate through all found resources
    for subject in result.subjects {
        // Get the full resource
        match store.get_resource(&subject.clone()).await {
            Ok(resource) => {
                // Try to get the shortname and description
                let shortname = resource
                    .get_shortname("shortname", &store)
                    .await
                    .map(|v| v.to_string())
                    .unwrap_or_else(|_| "No shortname".to_string());

                let description = resource
                    .get_shortname("description", &store)
                    .await
                    .map(|v| v.to_string())
                    .unwrap_or_else(|_| "No description".to_string());

                println!("\nClass: {}", shortname);
                println!("Subject: {}", subject);
                println!("Description: {}", description);
            }
            Err(e) => eprintln!("Error fetching resource {}: {}", subject, e),
        }
    }

    Ok(())
}