Documentation Index
Fetch the complete documentation index at: https://mintlify.com/nickruigrok/baseflare/llms.txt
Use this file to discover all available pages before exploring further.
defineTable creates a TableBuilder from a map of field names to validators. The TableBuilder it returns is passed as a value inside the tables object given to defineSchema() — you never instantiate a table directly. Validators come from the v.* namespace exported by baseflare/values, which handles type coercion, defaults, and optional fields uniformly across the client and server.
Signature
Parameters
A plain object where each key is a field name and each value is a validator from
v.*. Field names must be valid identifiers and must not start with _ (those
are reserved for framework-managed fields such as _id and _createdAt). At
least one field is required.Returns
ATableBuilder<TFields> object. TableBuilder extends TableDefinition and exposes a single chainable method, .index().
TableBuilder.index(name, fields, options?)
Adds an index to the table definition. Returns a new TableBuilder with the index appended — defineTable and .index() are immutable and safe to store and share.
The index name. Must match
/^[A-Za-z][A-Za-z0-9_]*$/. Combined with the table
name to produce the final SQL identifier, e.g. todos_by_owner. Must be unique
within the table.The ordered list of field names to include in the index. Each name must exist in
the table definition. At least one field is required. Field order matters — it
determines the left-to-right column order in the resulting
CREATE INDEX statement.Optional configuration object. Currently supports one key:
partition?: boolean— marks this index as the table’s partition index. See the Partition Indexes section below.
Throws
SchemaErrorif the index name duplicates an existing index on the same table.SchemaErrorifpartition: trueis passed when a partition index is already registered on this builder.
Validation Rules
defineTable validates these constraints immediately at call time:
- The
fieldsobject must contain at least one entry. - Every field name must match
/^[A-Za-z][A-Za-z0-9_]*$/and must not start with_. - The names
AND,OR, andNOTare reserved for query filter logic and may not be used as field names. - Every value in
fieldsmust be a Baseflare validator (an object with avalidatemethod). - For
.index(): thefieldsarray must not be empty. - For
.index(): every listed field name must already exist in the table’s field map.
Generated SQL
Indexes are stored asjson_extract() expressions over the _data JSON column. A single-field index generates:
_id TEXT PRIMARY KEY column and a _data TEXT NOT NULL column — you never declare those yourself.
Partition Indexes
A partition index is a hint to the Baseflare runtime that most reads and writes for a given table cluster around a natural grouping: a channel, a project, a tenant, a user. Baseflare uses this annotation to track per-partition version counters, which allows the real-time subscription system to cheaply detect changes within a partition without scanning the entire table. Use{ partition: true } when there is a clear dominant access pattern:
- Each table may have at most one partition index.
- Partition indexes may only reference scalar field types (
boolean,enum,id,literal,number,string). - When a table has exactly one index and no
partitionoption is provided, that index is automatically treated as the partition index. - When a table has multiple indexes, you must explicitly mark one with
{ partition: true }or opt every index out with{ partition: false }.