Declare a Postgres table in the records deploy phase and the platform gives you, with no backend code: validated REST CRUD (+ bulk + aggregate + count), composite field types, full-text search, row/column RBAC, soft delete, live SSE updates, record.* workflow triggers, an audit spine with actor provenance and English event summaries, gipity records CLI CRUD, and auto-generated table/form UI components.
One write path. Every write - REST, the gipity records CLI, a function's records service, workflow record steps and records llm-step tool, bulk import - flows through the same validation + audit + event pipeline. A raw db.query() INSERT from a function skips validation and audit (no field checks, no history entry, no actor); it still reaches the live stream and fires record.* workflow triggers, because the platform captures every change to a declared table in the database itself. In a function, use the injected records service when any of those matter: records.list/get/create/update/remove/history(table, ...), gated by the function's tables: list (writes are audited as FUNCTION, attributed by function name).
Declaring tables (gipity.yaml)
- name: records
type: records # AFTER the database phase - tables must exist
tables:
- table: deals
auth_level: user # public (anyone, signed out too, reads AND writes) | user (any signed-in caller) | member (default: owner + project members only; others get 403)
searchable: true # full-text search over text columns (q= param)
auto_number: { prefix: DEAL } # optional: new rows get DEAL0001001, DEAL0001002, ... (pad: 7, column: number by default)
# append_only: true # optional, ONE-WAY: rows can be added, never changed or deleted (see below)
fields:
- { name: name, type: text, required: true, title: true }
- { name: stage, type: select, options: { values: [Lead, Proposal, Won, Lost] } }
- { name: value, type: currency, label: Deal value }
- { name: owner_id, type: relation, label: Owner, options: { table: people, display: full_name } }
- { name: notes, type: textarea, section: Details, help: Internal notes }
With auth_level: user and no row policies, every signed-in caller can read, update and delete every row. For per-user data, add row policies (gipity rbac) or write through a function that filters on ctx.auth.userGuid.
Field metadata is optional per column - declared fields are coerced + validated on every write with self-correcting errors ('stage' must be one of: Lead, Proposal, Won, Lost (got 'Wonn')); undeclared columns pass through and Postgres validates them.
Types: text, textarea, number, boolean, date (YYYY-MM-DD), select, tags (list of short values on a plain TEXT column - send ["party","co-op"] or a string, stored/returned as "party, co-op", so ilike filters, q= search and sort all just work; options: {values} restricts them), json (objects only), and composites stored as JSONB in your column: currency {amountMicros, currencyCode} (accepts a plain number), name {firstName, lastName} (accepts "Ada Lovelace"), emails/phones/links (accept a bare string), address. relation describes an existing FK column (options: {table, display}); the value stays the raw id and Postgres enforces integrity.
Per-field keys: label, required (enforced on create), title (names the record in audit summaries), hide/section/help (drive generated UIs; order = declaration order).
Append-only tables (append_only: true) accept inserts and nothing else, for everyone, the owner included: the Records API answers 403 to update, delete, soft delete, ?purge=1, restore and bulk update/delete, and the database itself refuses UPDATE, DELETE and TRUNCATE from a function's db.query() or a migration. A migration also can't drop the table, drop or retype its columns, rename it, or remove the guard; adding a column is fine. Use it for command logs, ledgers and audit trails. It is one-way: once deployed, every later deploy must keep append_only: true (leaving it out fails the deploy), it can't be combined with soft_delete_column, and gipity records config <t> --append-only turns it on without a deploy but nothing turns it off. Dropping the whole database (gipity db drop) or deleting the account still removes it, and gipity db restore can't roll it back (restoring would rewrite it). gipity test writes to a throwaway copy without the database guard, but Records API calls in tests still get the 403.
Postgres VIEWs can be declared too - they get the full read API (list/filter/sort/aggregate) and render in the UI components read-only. The Records API refuses every write to a view (400); write to the base table instead.
Table schema (the migration side)
The table itself is a plain migrations/NNN-*.sql CREATE TABLE; Records layers onto whatever columns it finds. Only three columns are special, all optional:
- Primary key - defaults to
id. If yours is named differently (e.g. ashort_guidPK), addprimary_key: <col>to the table entry./history,GET /records/<t>/<id>, and SSE all key off it. updated_at- if the table has anupdated_at TIMESTAMPTZcolumn, Records bumps it automatically on every update and restore; give itDEFAULT NOW()so new rows have it too. Do not write a trigger for it: migrations run on a managed database that blocksCREATE FUNCTION/CREATE TRIGGER, so the textbookupdated_attrigger fails the deploy. Pair it withcreated_at TIMESTAMPTZ DEFAULT NOW()for sortable timestamps with zero trigger code. (For any other derived column, use a PostgresGENERATEDcolumn or compute it in a function - never a trigger.)- Soft delete - add a nullable
deleted_at TIMESTAMPTZcolumn and declaresoft_delete_column: deleted_at;DELETEthen stamps it instead of removing the row, and the recycle bin (?only_deleted=1,restore) works. Omit both to hard-delete. - Auto-number -
auto_number: { prefix, pad, column }fillscolumn(aTEXTcolumn, defaultnumber) on every create that doesn't set it: prefix + a counter starting at 1001, zero-padded topaddigits (default 7). The deploy fails if the column is missing. Dropping the block fromgipity.yamlleaves the numbering on; turn it off withgipity records config <t> --auto-number none.gipity testruns number from their own counter (restarting at 1001 with each test file's fresh database), so tests never use up live numbers.
CREATE TABLE IF NOT EXISTS deals (
id BIGSERIAL PRIMARY KEY,
name TEXT NOT NULL,
stage TEXT,
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW(), -- bumped by Records on update; no trigger
deleted_at TIMESTAMPTZ -- soft_delete_column: deleted_at
);
REST API
Base: https://a.gipity.ai/api/<PROJECT_GUID> - auth via X-App-Token (+ session cookie for user/member), or X-Api-Key.
From the browser, don't call these by hand - gipity.js mints the token for you and Gipity.records.* mirrors the endpoints below one-for-one, returning the unwrapped data: list(t, params) → {rows, total} · get(t, id) · create(t, data) · update(t, id, data) · remove(t, id, {purge}) · restore(t, id) · count(t, params) (a string is the filter) · aggregate(t, params) · schema(t) · history(t, id) · tableHistory(t) · comments(t, id) · addComment(t, id, text, {internal}) · createMany(t, rows) · stream(t, {onChange, filter}) → {stop()} · views.list/save/update/remove. params are the query params below (filter, any, sort, limit, offset, fields, q, include_deleted, only_deleted).
GET /records/<t>?filter=&any=&sort=&limit=&offset=&fields=&q=→{data, meta:{total}}. Filter ops:eq,neq,gt,gte,lt,lte,like,ilike,in,is_null,not_null;inis pipe-separated (id:in:1|2|3); filters comma-join as AND.like/iliketake a raw SQL pattern - YOU supply the%(name:ilike:%ada%; no%= exact match); for substring/word search useq=instead.any=is an OR group with the same grammar, ANDed withfilter(any=owner:eq:me,shared:eq:true= at least one matches).GET /records/<t>/<id>·POST /records/<t>·PUT /records/<t>/<id>·DELETE /records/<t>/<id>(soft delete when the table declaressoft_delete_column;?purge=1hard-deletes the row AND erases its history - owner/editor, use it to scrub probe rows)- Linked fields (hop one relation deep, from the same metadata): project parent columns (
fields=name,company.name→ flat dotted keys in the JSON), filter (filter=company.industry:eq:software, works inany=too), sort (sort=company.name:asc), and aggregate (group_by=company.industry- instant reports). The prefix is the relation field minus_id(or the field name itself). Missing and soft-deleted parents come back NULL; the target table's auth level and RBAC still apply (row policies on the target block the hop with a clear error); errors name the available relations and columns so callers self-correct. Not available on SSE streams (linked-field conditions are ignored there). - Saved views (platform data, sign-in required):
GET|POST /records/<t>/views,PUT|DELETE /records/<t>/views/<id>- named, shareable view configs ({name, view_type, config, shared}; the config blob is the UI's view state). Everyone saves private views; sharing needs owner/editor. SDK:Gipity.records.views.list/save/update/remove. - Recycle bin (owner/editor only):
?only_deleted=1lists deleted rows,?include_deleted=1includes them (list/count/get),POST /records/<t>/<id>/restoreun-deletes with arestoreaudit event. POST|PUT|DELETE /records/<t>/bulk(arrays).?source=importon any write route marks the writes IMPORT for CSV import tooling.GET /records/<t>/count?filter=&any=·GET /records/<t>/aggregate?group_by=&aggregate=count,sum&column=_,valueGET /records/<t>/<id>/history- audit events:source+detail.summary(below)GET|POST /records/<t>/<id>/comments- a comment thread on any record (POST{text, is_internal}; GET lists oldest first). Comments are rows in your app's owncommentstable, shared by every table and written through Records (validated, audited). Create it in a migration to turn comments on; without it these return 404 and<gipity-record-form>hides its comments pane:CREATE TABLE comments (id BIGSERIAL PRIMARY KEY, table_name TEXT NOT NULL, record_id TEXT NOT NULL, text TEXT NOT NULL, is_internal BOOLEAN NOT NULL DEFAULT false, created_by INT, created_at TIMESTAMPTZ NOT NULL DEFAULT NOW());Reading and posting follow the commented table's auth level; the record must exist.GET /records/<t>/stream- SSE change feed that never misses an event (details below)GET /records/<t>/history?format=jsonl- the table's WHOLE audit history as a JSON Lines download, oldest first (owner/editor). CLI:gipity records history <t> --jsonl > history.jsonlGET /schema/<t>- live columns merged with the records config + field metadata: the one contract UI generators consume
Live change stream (SSE)
GET /records/<t>/stream (Accept: text/event-stream; same auth as the REST API, X-Api-Key works for a device; filter=, any= and fields= narrow it). Events:
record.created{...record}·record.updated{id, changes: {field: [old, new]}, record}·record.deleted{id}- every event has an
id:. On reconnect send the last one back as theLast-Event-IDheader (a browserEventSourcedoes this by itself) or as?last_event_id=and the stream replays everything you missed, in order, then continues live, with no gap and no duplicate. Missed events are kept for 24 hours (up to 100,000 per table). event: reset{reason}means events after your id may be gone (older than 24 hours, or an id the stream doesn't know): reload the table through the REST API, then keep reading; the reset carries a freshid:to resume from.- a row too large to inline (over 64 KB) arrives as
{id, record: null, record_omitted: true}(updates alsochanges: null): fetch it withGET /records/<t>/<id>. It is never dropped, and row policies still decide who gets it. - a
: keepalivecomment every 15 seconds, so proxies and NAT keep the connection open; if two beats go missing, reconnect. - row policies (
gipity rbac) and column restrictions apply to the stream the same as to a list read. - at most 10 open streams per caller per app: per API key for a key, otherwise per signed-in user.
- Every write to a declared table streams, whoever makes it: the REST API, CLI, a function's
recordsservice, workflow steps, and also a function's rawdb.query(), a migration or a workflow SQL step. Only committed changes stream (a rolled-backdb.txnever does), in commit order, each carrying the row as the table holds it when the event goes out (an insert updated in the same transaction arrives already updated). A soft delete (setting thesoft_delete_column, by any path) streams asrecord.deleted. The capture is a trigger the platform attaches when the table is declared in therecordsphase (and removes when a deploy no longer declares it); dropping it from a migration is your call and stops raw writes from streaming until the next deploy.
A device that must never miss a command: keep the last id: it processed on disk, reconnect with it after any drop, and on reset re-read the pending commands with GET /records/<t>?filter=.... Pair it with an append-only table so the command log can't be edited after the fact. In Python, the registry's gipity_device client does all of this (client.subscribe(table, on_event, cursor_file=..., on_reset=...): heartbeat timeout, reconnect with backoff, Last-Event-ID resume, a cursor file that survives restarts, and omitted rows fetched by id); see examples/python for a full device walkthrough.
Provenance + English audit history
Every write records WHO (user), and HOW: source = MANUAL (signed-in user) / API (API key, attributed by key name) / FUNCTION (a function's records service, attributed by function name) / WORKFLOW (record steps, attributed by workflow name) / FORM (anonymous public-table write) / IMPORT (any write with ?source=import). Each event carries a one-line English summary derived from field labels - deal-won-followup created deal task "Follow up: Acme won" - so /history is prompt-ready: an AI brief over a record (or a whole table) is one LLM call over the event stream, not a RAG project. CLI: gipity records history <table> [id] (omit the id for the table-wide feed). History payloads are de-identified (a display-name actor, never DB ids); the whole-table feed is owner/editor only (per-record history follows the table's read auth).
Workflows
record.after_insert/update/delete triggers fire on Records API writes only. A workflow record step writes through the same path, so its writes are validated, audited (WORKFLOW provenance), and can chain further triggers (depth-capped). See workflow.
From the CLI
gipity records tables (the configured tables) / list <table> (rows: -q, --filter, --sort, --only-deleted) / get <table> <id> / create <table> / update <table> <id> / delete <table> <id> / restore <table> <id> / history <table> [id] - same write path as the REST API, with provenance and self-correcting errors. gipity records config <table> --auth <level> changes a table's exposure without a redeploy, --append-only makes it append-only for good, and --auto-number <prefix> (--auto-number-pad, --auto-number-column, none to turn off) its numbering; for a table declared in gipity.yaml, the next deploy puts back the declared auth_level and auto_number, so change them there to keep them.
Auto-generated UI (Gipity Views)
Load after the client SDK and get ServiceNow-style list + form for free:
<script defer src="https://media.gipity.ai/client/v1/gipity.js" data-app="<PROJECT_GUID>"></script> <!-- your project guid: gipity project info -->
<script defer src="https://media.gipity.ai/views/v1/gipity-views.js"></script>
<gipity-records table="deals" live></gipity-records>
<gipity-records> = table + "New" button + slide-over form. Or compose <gipity-table> (sort, per-column filter chips, search, pagination, CSV export, SSE live updates, composite-aware cells, relation display + typeahead) and <gipity-record-form> (type-appropriate widgets, sections, inline self-correcting validation errors, history pane with provenance, comments pane when the app has a comments table) yourself. Columns and widgets come from the field metadata, with live-introspection fallback for undeclared tables. Theme with --gv-* CSS variables. On a user or member table the components wait for sign-in: a signed-out visitor sees "Sign in to see these records." and no requests are made, and the component loads itself on sign-in, so put it on the page as-is (no mount-after-login code).
Drag-and-drop board: <gipity-kanban table="deals" group-by="stage" metric="amount" live> - one column per value of a declared select field, cards drag between them, and the drop is a normal validated + audited write that fires record.after_update. Same filter/sort attributes as the table, so "flip this list into a board" is a second element, never hand-written drag code. Add an integer position column to persist manual card order. <gipity-saved-views table="deals" target="deals-list"> saves and re-applies any of these components' filter+sort state as platform data (no app table).
Common mistakes
- Writing with
db.query()and expecting validation/audit - only Records writes (REST, CLI, a function'srecordsservice, workflow steps) get them. Raw writes do stream and firerecord.*triggers, so a raw UPDATE inside a workflow on its own trigger table re-triggers it (capped at 5 levels). - Declaring the
recordsphase before thedatabasephase (table doesn't exist yet → skipped with a warning). - Composite columns not JSONB -
currency/name/emails/... need a JSONB column. id:in:1,2,3- commas separate filters;invalues are pipe-separated:id:in:1|2|3.- Expecting record triggers to fire from
gipity testwrites - test-schema writes are deliberately skipped. - Removing
append_only: truefromgipity.yaml- the deploy fails; append-only can't be turned off.