ChatiumFor developersPlaygroundPricing
Sign in

HeapTableRepo.create

Creates a new record in the heap table.

The provided object with values is validated against the table schema.

Usage/Signature

table.create(ctx, fields)
  • Arguments

    • ctx*: app.Ctx
      Request context. Used for internal implementation and allows executing the request in the appropriate transaction.

    • fields: object
      An object with fields and values that correspond to the table schema.

      All fields declared in the schema must be present, except those declared with modifiers: Heap.Optional, Heap.Nullable, and Heap.NonRequired. The same rule applies to nested objects.

      Fields whose values are not provided are automatically filled with default values if they exist.

  • Return Value: Promise<HeapObject>

Examples


Creating a record with different types of optional fields and a nested object.

const Tasks = Heap.Table('tasks', {
  title: Heap.String(),
  priority: Heap.NonRequired(Heap.Integer(), 3),
  project: Heap.Nullable(Heap.RefLink('projects')),
  due: Heap.Optional(Heap.DateTime()),
  customerInfo: Heap.Optional(Heap.Object({
    name: Heap.String(),
    email: Heap.Nullable(Heap.String({ format: 'email' })),
  })),
})
const newTask = await Tasks.create(ctx, {
  title: 'Call the client',
  customerInfo: {
    name: 'Ivan Petrov',
  },
})
/* {
     title: 'Call the client',
     priority: 3,
     project: null,
     customerInfo: {
       name: 'Ivan Petrov',
       email: null,
     },
   } */