Files
db/herodb_old/src/cmd/dbexample_biz/README.md
2025-04-22 12:53:17 +04:00

1.9 KiB

Business Models Example

This example demonstrates the business models in HeroDB, showcasing a complete business transaction flow from product definition to payment processing.

Features Demonstrated

  1. Product Definition: Creating two types of server node products with different components and pricing
  2. Component Definition: Defining the parts that make up each server node (CPU, RAM, Storage, GPU)
  3. Pricing Setup: Setting up prices for products using the Currency model
  4. Product Availability: Checking which products can be purchased based on their status and availability
  5. Sales Process: Simulating a customer purchasing a product
  6. Invoice Generation: Creating an invoice for the sale
  7. Payment Processing: Processing a payment for the invoice and updating its status

Business Flow

The example follows this business flow:

Define Products → Check Availability → Customer Purchase → Generate Invoice → Process Payment

Models Used

  • Product & ProductComponent: For defining server nodes and their components
  • Customer: For representing the buyer
  • Sale & SaleItem: For recording the purchase transaction
  • Invoice & InvoiceItem: For billing the customer
  • Payment: For recording the payment

Running the Example

To run this example, use:

cargo run --bin dbexample_biz

The output will show each step of the business process with relevant details.

Key Concepts

  • Builder Pattern: All models use builders for flexible object creation
  • Status Tracking: Sales and invoices have status enums to track their state
  • Relationship Modeling: The example shows how different business entities relate to each other
  • Financial Calculations: Demonstrates tax and total calculations

This example provides a template for implementing business logic in your own applications using HeroDB.