Skip to content

Entities

The entity block defines a data model in your Terranova application. An entity can contain a schema, custom queries, and views — but all sub‑blocks are optional.

entity "User" {
    schema { ... }      
    queries { ... }     
    views { ... }       
}

Sub‑blocks

Block Required Description
schema Defines fields, primary key, and relationships
queries Custom SQL queries (raw or composed)
views HTML templates bound to routes

Examples

Minimal entity (empty)

entity "Log" {
    // no schema, queries, or views
}

This creates an entity with no database table and no auto‑generated behavior.

Entity with only a schema

entity "Task" {
    schema {
        pk "id" type="int"
        field "title" type="string"
        field "completed" type="bool"
    }
}

Entity with only queries

entity "Report" {
    queries {
        get "daily_summary" sql="SELECT date, count(*) as count FROM events GROUP BY date"
    }
}

Entity with only views

entity "Page" {
    views {
        template "/about" html="<h1>About Us</h1>"
    }
}

Entity with all blocks

entity "User" {
    schema {
        pk "id" type="int"
        field "name" type="string"
    }
    queries {
        get "user_by_id" sql="SELECT * FROM user WHERE id = :id" {
            param "id" type="int"
        }
    }
    views {
        template "/" query="user_by_id" html="<h1>{{data.name}}</h1>"
    }
}

What Terranova Does With the Entity

  • Parses the entity block and its optional sub‑blocks.
  • Does not enforce any specific structure — you can mix and match schema, queries, and views as needed.
  • Delegates processing of each sub‑block to their respective documentation.

See Also

  • Schemas – Defining database structure and relationships
  • Queries – Custom SQL and composed queries
  • Views – HTML templates and routing
  • Application – Root configuration ```