Heap.Table
Declares a heap table. This is the main and only supported way to "create" a heap table.
Usage / Signature
import { Heap } from '@app/heap'
const Table = Heap.Table(tableName, fields)
The Heap.Table
function can only be called at the top level of a module, meaning it cannot be invoked within the body of a function or any other block. Additionally, you must directly use the Heap
object from the import in this module; you cannot do:
import { Heap } from '@app/heap'
const RenamedHeap = Heap
const table = RenamedHeap.Table(...)
Arguments
-
<b id="tableName">tableName</b>:
string
<b style="color:red">*</b>
The name of the table. It must be unique within the account where the table code file is created.The name may only contain Latin letters (both lowercase and uppercase), digits, the underscore character (
_
), as well as the dot (.
) and hyphen (-
), but only in the middle of the name as separators.The name must be a simple string literal written directly in the call to Heap.Table, meaning it cannot be a variable, a simple expression with concatenation, or a template with interpolation. This is checked at the compilation stage of the file.
-
<b id="fields">fields</b>:
{ [key: string]: HeapSchema }
<b style="color:red">*</b>
An object whose keys are the names of the top-level fields of the table, and whose values are schemas describing their types (e.g.,Heap.String()
).Field names may only contain Latin letters (both lowercase and uppercase), digits, the underscore character (
_
), and must not start with a digit.Since the table declaration at the top level represents a JSON object with fields, the description of the table fields is fully analogous to the description of fields in Heap.Object.
Return Value
A repository object HeapTableRepo, which provides access to CRUD operations on the table.
Examples
Declaring and using a simple heap table
const issues = Heap.Table('issues', {
title: Heap.NonEmptyString(),
done: Heap.NonRequired(Heap.Boolean(), false),
deadline: Heap.Nullable(Heap.DateTime()),
})
const firstIssue = await issues.create(ctx, {
title: 'first',
})
await issues.update(ctx, {
id: firstIssue.id,
deadline: new Date(2022, 11, 31),
})