Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Globals

Globals are single-document collections for site-wide settings. Each global stores exactly one row.

Definition

Define globals in globals/*.lua using crap.globals.define():

-- globals/site_settings.lua
crap.globals.define("site_settings", {
    labels = {
        singular = "Site Settings",
    },
    fields = {
        crap.fields.text({ name = "site_name", required = true, default_value = "My Site" }),
        crap.fields.text({ name = "tagline" }),
    },
})

Config Properties

PropertyTypeDefaultDescription
labelstable{}Display names
labels.singularstringslugSingular name (e.g., “Site Settings”)
labels.pluralstringslugPlural name
fieldsFieldDefinition[]{}Field definitions
hookstable{}Same lifecycle hooks as collections
accesstable{}Same access control as collections
versionsboolean or tablenilVersioning config (same as collections)
liveboolean or stringnilLive update broadcasting (same as collections)
mcptable{}MCP tool config. { description = "..." }

Database Table

Each global gets a table named _global_{slug} with a single row where id = 'default'. The row is auto-created on startup.

Globals always have created_at and updated_at timestamp columns.

Differences from Collections

FeatureCollectionsGlobals
DocumentsMultipleExactly one
Table name{slug}_global_{slug}
CRUD operationsfind, find_by_id, create, update, deleteget, update
TimestampsOptional (timestamps = true)Always enabled
Auth / UploadSupportedNot supported
VersionsSupportedSupported
Live updatesSupportedSupported
MCPSupportedSupported

Lua API

-- Get current value
local settings = crap.globals.get("site_settings")
print(settings.site_name)

-- Update
crap.globals.update("site_settings", {
    site_name = "New Name",
    tagline = "A fresh start",
})

gRPC API

# Get
grpcurl -plaintext -d '{"slug": "site_settings"}' \
    localhost:50051 crap.ContentAPI/GetGlobal

# Update
grpcurl -plaintext -d '{
    "slug": "site_settings",
    "data": {"site_name": "Updated Site"}
}' localhost:50051 crap.ContentAPI/UpdateGlobal