Skip to main content
Entities are the core building blocks of ChameleonDB schemas. Each entity represents a domain concept with fields, relationships, and constraints.

Entity Definition

An entity is defined using the entity 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., User not Users)
  • 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

Keep entities focused - Each entity should represent a single, clear domain concept
Use meaningful names - Entity names should be immediately understandable by domain experts
Group related fields - Use comments to organize fields, relations, and annotations

Next Steps

Field Types

Learn about supported field types

Relations

Define relationships between entities

Constraints

Add validation and constraints

Annotations

Optimize with backend annotations