implement more models and rhai examples
This commit is contained in:
@@ -1,11 +1,20 @@
|
||||
// Get the database instance
|
||||
let db = get_db();
|
||||
|
||||
// Create a new calendar
|
||||
let calendar = calendar__builder(1);
|
||||
calendar.name = "My First Calendar";
|
||||
set_description(calendar, "A calendar for testing Rhai integration");
|
||||
// Create a new calendar using the constructor and builder methods
|
||||
print("Creating a new calendar with ID 1 via registered constructor...");
|
||||
let calendar = new_calendar(1).
|
||||
name("My First Calendar").
|
||||
description("A calendar for testing Rhai integration");
|
||||
|
||||
let event = new_event(1).
|
||||
title("My First Event").
|
||||
description("An event for testing Rhai integration")
|
||||
.add_attendee(new_attendee(1));
|
||||
|
||||
calendar.add_event(1);
|
||||
|
||||
print("Type of calendar object: " + type_of(calendar));
|
||||
print("Created calendar: " + calendar.name);
|
||||
|
||||
// Save the calendar to the database
|
||||
@@ -16,20 +25,24 @@ print("Calendar saved to database");
|
||||
if calendar_exists(db, 1) {
|
||||
let retrieved_calendar = get_calendar_by_id(db, 1);
|
||||
print("Retrieved calendar: " + retrieved_calendar.name);
|
||||
let desc = get_description(retrieved_calendar);
|
||||
if desc != "" {
|
||||
// Access the 'description' field directly.
|
||||
// Note: 'description' is Option<String>. Rhai handles options.
|
||||
// You might want to check for 'is_some()' or 'is_none()' or use 'unwrap_or()' pattern if needed.
|
||||
let desc = retrieved_calendar.description;
|
||||
if desc != () && desc != "" { // Check against '()' for None and empty string
|
||||
print("Description: " + desc);
|
||||
} else {
|
||||
print("No description available");
|
||||
print("No description available or it's None");
|
||||
}
|
||||
} else {
|
||||
print("Failed to retrieve calendar with ID 1");
|
||||
}
|
||||
|
||||
// Create another calendar
|
||||
let calendar2 = calendar__builder(2);
|
||||
calendar2.name = "My Second Calendar";
|
||||
set_description(calendar2, "Another calendar for testing");
|
||||
print("Creating a new calendar with ID 2 using builder methods...");
|
||||
let calendar2 = new_calendar(2).
|
||||
name("My Second Calendar").
|
||||
description("Another calendar for testing");
|
||||
|
||||
set_calendar(db, calendar2);
|
||||
print("Second calendar saved");
|
||||
@@ -38,8 +51,9 @@ print("Second calendar saved");
|
||||
let all_calendars = get_all_calendars(db);
|
||||
print("Total calendars: " + all_calendars.len());
|
||||
|
||||
for calendar in all_calendars {
|
||||
print("Calendar ID: " + get_id(calendar) + ", Name: " + calendar.name);
|
||||
for cal_item in all_calendars { // Renamed loop variable to avoid conflict if 'calendar' is still in scope
|
||||
// Access 'base_data.id' and 'name' fields directly
|
||||
print("Calendar ID: " + cal_item.base_data.id + ", Name: " + cal_item.name);
|
||||
}
|
||||
|
||||
// Delete a calendar
|
||||
|
Reference in New Issue
Block a user