db/heromodels/examples/library_rhai/library.rhai
2025-06-12 05:22:17 +03:00

78 lines
2.6 KiB
Plaintext

// heromodels/examples/library_rhai/library.rhai
print("--- Testing Library Rhai Module ---");
// --- Image ---
print("\n1. Creating and saving an image...");
let my_image = new_image()
.title("A Beautiful Sunset")
.description("A photo taken from a drone.")
.url("https://example.com/sunset.jpg")
.width(1920)
.height(1080);
let saved_image = save_image(my_image);
print(" > Saved image with ID: " + saved_image.id);
let image_id = saved_image.id;
// --- PDF ---
print("\n2. Creating and saving a PDF...");
let my_pdf = new_pdf()
.title("Rust Programming Guide")
.description("A comprehensive guide to Rust.")
.url("https://example.com/rust.pdf")
.page_count(500);
let saved_pdf = save_pdf(my_pdf);
print(" > Saved PDF with ID: " + saved_pdf.id);
let pdf_id = saved_pdf.id;
// --- Markdown ---
print("\n3. Creating and saving a Markdown document...");
let my_markdown = new_markdown()
.title("Meeting Notes")
.description("Notes from the weekly sync.")
.content("# Meeting Notes\n\n- Discussed project status.\n- Planned next sprint.");
let saved_markdown = save_markdown(my_markdown);
print(" > Saved Markdown with ID: " + saved_markdown.id);
let markdown_id = saved_markdown.id;
// --- Collection ---
print("\n4. Creating a collection and adding items...");
let my_collection = new_collection()
.title("My Awesome Collection")
.description("A collection of various media.")
.add_image(image_id)
.add_pdf(pdf_id)
.add_markdown(markdown_id);
let saved_collection = save_collection(my_collection);
print(" > Saved collection with ID: " + saved_collection.id);
let collection_id = saved_collection.id;
// --- Verification ---
print("\n5. Verifying saved data...");
let fetched_collection = get_collection(collection_id);
print(" > Fetched collection: '" + fetched_collection.title + "'");
print(" > Collection contains " + fetched_collection.images + " image(s).");
print(" > Collection contains " + fetched_collection.pdfs + " pdf(s).");
print(" > Collection contains " + fetched_collection.markdowns + " markdown(s).");
let fetched_image = get_image(image_id);
print(" > Fetched image title: '" + fetched_image.title + "'");
if (fetched_image.url != "https://example.com/sunset.jpg") {
throw "Image URL mismatch!";
}
print(" > Image URL verified.");
// --- Deletion ---
print("\n6. Cleaning up database...");
delete_image(image_id);
print(" > Deleted image with ID: " + image_id);
delete_pdf(pdf_id);
print(" > Deleted PDF with ID: " + pdf_id);
delete_markdown(markdown_id);
print(" > Deleted Markdown with ID: " + markdown_id);
delete_collection(collection_id);
print(" > Deleted collection with ID: " + collection_id);