Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions lib/examples/try_query.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use atomic_lib::errors::AtomicResult;
use atomic_lib::{storelike::Query, Store, Storelike};

fn main() -> AtomicResult<()> {
// Initialize a new store
let store = Store::init()?;
// Populate it with some default data
store.populate()?;

// 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)?;

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) {
Ok(resource) => {
// Try to get the shortname and description
let shortname = resource
.get_shortname("shortname", &store)
.map(|v| v.to_string())
.unwrap_or_else(|_| "No shortname".to_string());

let description = resource
.get_shortname("description", &store)
.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(())
}
Loading