Entity Definition
An entity is defined using theentity keyword followed by a name and a block containing fields and relations:
Naming Convention
Entity names should:- Start with an uppercase letter
- Use PascalCase for multi-word names (e.g.,
OrderItem,UserProfile) - Be singular (e.g.,
UsernotUsers) - Represent a clear domain concept
Entity Structure
Entities contain three types of members:1. Fields
Data attributes that define the entity’s properties:2. Relations
Connections to other entities:3. Backend Annotations
Hints for storage optimization:Complete Example
Here’s a complete multi-entity schema demonstrating all features:Entity Validation
ChameleonDB validates entities at compile time:Primary Key Required - Each entity must have exactly one primary key field
Unique Names - Entity names must be unique within a schema
Valid References - All relation targets must reference existing entities
No Circular Ownership - Entities cannot form circular ownership dependencies
Best Practices
Next Steps
Field Types
Learn about supported field types
Relations
Define relationships between entities
Constraints
Add validation and constraints
Annotations
Optimize with backend annotations