Hero Models Examples
This directory contains example scripts demonstrating how to use the HeroDB models.
Available Models
Chat Models
heromodels_chat_group.vsh- Example usage of ChatGroup modelheromodels_chat_message.vsh- Example usage of ChatMessage model
Other Models
heromodels_calendar.vsh- Example usage of Calendar modelheromodels_calendar_event.vsh- Example usage of CalendarEvent modelheromodels_calendar_event_simple.vsh- Simple example of CalendarEvent modelheromodels_calendar_event_with_recurrence.vsh- Example with recurrence rulesheromodels_comments.vsh- Example usage of Comments helperheromodels_group.vsh- Example usage of Group modelheromodels_group_add_members.vsh- Example adding members to a groupheromodels_group_relationships.vsh- Example group relationshipsheromodels_group_with_members.vsh- Example group with membersheromodels_user.vsh- Example usage of User model
Running Examples
To run any example script, use the following command:
v -enable-globals run examples/hero/heromodels/<script_name>.vsh
For example:
v -enable-globals run examples/hero/heromodels/heromodels_chat_group.vsh
v -enable-globals run examples/hero/heromodels/heromodels_chat_message.vsh
Chat Models Overview
ChatGroup
Represents a chat channel or conversation with the following properties:
chat_type- Type of chat (public_channel, private_channel, direct_message, group_message)last_activity- Unix timestamp of last activityis_archived- Whether the chat group is archived
ChatMessage
Represents a message in a chat group with the following properties:
content- The message contentchat_group_id- Associated chat group IDsender_id- User ID of senderparent_messages- Referenced/replied messagesfs_files- IDs of linked filesmessage_type- Type of message (text, image, file, voice, video, system, announcement)status- Message status (sent, delivered, read, failed, deleted)reactions- Message reactionsmentions- User IDs mentioned in message
Implementation Details
The chat models are implemented in lib/hero/heromodels/:
chat_group.v- Contains ChatGroup struct and related functionalitychat_message.v- Contains ChatMessage struct and related functionality
Both models inherit from the base db.Base struct and implement the standard CRUD operations:
new()- Create a new instanceset()- Save to databaseget()- Retrieve from databasedelete()- Delete from databaseexist()- Check if exists in databaselist()- List all objects of this type