Production deployment with zinit config
This commit is contained in:
37
examples/osiris_example.rs
Normal file
37
examples/osiris_example.rs
Normal file
@@ -0,0 +1,37 @@
|
||||
/// Example: Running OSIRIS Rhai scripts
|
||||
///
|
||||
/// This example demonstrates how to use the OSIRIS Rhai engine
|
||||
/// to execute scripts that create and manipulate OSIRIS objects.
|
||||
///
|
||||
/// Prerequisites:
|
||||
/// - HeroDB running on localhost:6379
|
||||
/// - osiris crate added as dependency with rhai-support feature
|
||||
///
|
||||
/// Run with:
|
||||
/// ```bash
|
||||
/// cargo run --example osiris_example
|
||||
/// ```
|
||||
|
||||
use runner_rust::engine::osiris::run_osiris_script;
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!("🚀 OSIRIS Rhai Engine Example\n");
|
||||
|
||||
// Example 1: Inline script
|
||||
println!("Example 1: Inline Script");
|
||||
println!("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n");
|
||||
|
||||
let script = r#"
|
||||
print("Creating a note from inline script...");
|
||||
let note = note("notes");
|
||||
print(note);
|
||||
"#;
|
||||
|
||||
run_osiris_script(script, "redis://localhost:6379", 1)?;
|
||||
|
||||
println!("\n✅ Example completed!");
|
||||
println!("\nNote: Full OSIRIS integration requires adding osiris crate");
|
||||
println!(" as a dependency with the 'rhai-support' feature enabled.");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
54
examples/osiris_script.rhai
Normal file
54
examples/osiris_script.rhai
Normal file
@@ -0,0 +1,54 @@
|
||||
// OSIRIS Rhai Script Example
|
||||
// This script demonstrates creating and storing OSIRIS objects
|
||||
|
||||
print("=== OSIRIS Rhai Script Example ===\n");
|
||||
|
||||
// Create a note with fluent builder pattern
|
||||
print("Creating a note...");
|
||||
let note = note("notes")
|
||||
.title("My First Rhai Note")
|
||||
.content("This note was created from a Rhai script using the OSIRIS engine!")
|
||||
.tag("source", "rhai")
|
||||
.tag("project", "osiris")
|
||||
.tag("priority", "high")
|
||||
.mime("text/plain");
|
||||
|
||||
print(`Note created: ${note.get_title()}`);
|
||||
|
||||
// Store the note in HeroDB
|
||||
print("Storing note...");
|
||||
let note_id = put_note(note);
|
||||
print(`✓ Note stored with ID: ${note_id}\n`);
|
||||
|
||||
// Retrieve the note
|
||||
print("Retrieving note...");
|
||||
let retrieved_note = get_note("notes", note_id);
|
||||
print(`✓ Retrieved: ${retrieved_note.get_title()}`);
|
||||
print(` Content: ${retrieved_note.get_content()}\n`);
|
||||
|
||||
// Create an event
|
||||
print("Creating an event...");
|
||||
let event = event("calendar", "Team Meeting")
|
||||
.description("Weekly team sync")
|
||||
.location("Conference Room A")
|
||||
.category("meetings")
|
||||
.all_day(false);
|
||||
|
||||
print(`Event created: ${event.get_title()}`);
|
||||
|
||||
// Store the event
|
||||
print("Storing event...");
|
||||
let event_id = put_event(event);
|
||||
print(`✓ Event stored with ID: ${event_id}\n`);
|
||||
|
||||
// Query notes by tag
|
||||
print("Querying notes by tag (project=osiris)...");
|
||||
let ids = query("notes", "tags:tag", "project=osiris");
|
||||
print(`✓ Found ${ids.len()} note(s) with tag project=osiris`);
|
||||
|
||||
for id in ids {
|
||||
let n = get_note("notes", id);
|
||||
print(` - ${n.get_title()}`);
|
||||
}
|
||||
|
||||
print("\n=== Script completed successfully! ===");
|
||||
46
examples/test_osiris.rs
Normal file
46
examples/test_osiris.rs
Normal file
@@ -0,0 +1,46 @@
|
||||
/// Quick test of OSIRIS Rhai integration
|
||||
///
|
||||
/// Run with:
|
||||
/// ```bash
|
||||
/// cargo run --example test_osiris
|
||||
/// ```
|
||||
|
||||
use runner_rust::engine::osiris::create_osiris_engine;
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!("🧪 Testing OSIRIS Rhai Engine\n");
|
||||
|
||||
// Test 1: Create engine
|
||||
println!("Test 1: Creating OSIRIS engine...");
|
||||
let engine = create_osiris_engine("redis://localhost:6379", 1)?;
|
||||
println!("✓ Engine created successfully\n");
|
||||
|
||||
// Test 2: Run simple script
|
||||
println!("Test 2: Running simple script...");
|
||||
let script = r#"
|
||||
print("Hello from OSIRIS Rhai!");
|
||||
|
||||
// Create a note
|
||||
let note = note("test_notes")
|
||||
.title("Test Note")
|
||||
.content("This is a test")
|
||||
.tag("test", "true");
|
||||
|
||||
print("Note created: " + note.get_title());
|
||||
"#;
|
||||
|
||||
match engine.eval::<()>(script) {
|
||||
Ok(_) => println!("✓ Script executed successfully\n"),
|
||||
Err(e) => {
|
||||
println!("✗ Script error: {}\n", e);
|
||||
println!("Note: This is expected if HeroDB is not running");
|
||||
}
|
||||
}
|
||||
|
||||
println!("✅ Tests completed!");
|
||||
println!("\nTo run full integration:");
|
||||
println!("1. Start HeroDB: cd ../herodb && cargo run --release");
|
||||
println!("2. Run: cargo run --example test_osiris");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user