Type alias CreateTableColumnDefinitions

CreateTableColumnDefinitions: Record<string, LooseCreateTableColumnDefinition | StrictCreateTableColumnDefinition>
Overview

Represents the syntax for defining a new column through the bespoke Data API schema definition syntax, in which there are two branching ways to define a column.

Example

await db.createTable('my_table', {
definition: {
columns: {
id: 'uuid',
name: { type: 'text' },
set: { type: 'set', valueType: 'text' },
},
primaryKey: ...,
},
});
The "loose" column definition

The loose column definition is a shorthand for the strict version, and follows the following example form:

columns: {
textCol: 'text',
uuidCol: 'uuid',
}

In this form, the key is the column name, and the value is the type of the scalar column.

If you need to define a column with a more complex type (i.e. for maps, sets, lists, and vectors), you must use the strict column definition.

Plus, while it still provides autocomplete, the loose column definition does not statically enforce the type of the column, whereas the strict column definition does.

The "strict" column definition

The strict column definition is the more structured way to define a column, and follows the following example form:

columns: {
uuidCol: { type: 'uuid' },
mapCol: { type: 'map', keyType: 'text', valueType: 'int' },
listCol: { type: 'list', valueType: 'text' },
vectorCol: { type: 'vector', dimension: 3 },
}

In this form, the key is the column name, and the value is an object with a type field that specifies the type of the column.

The object may also contain additional fields that are specific to the type of the column:

  • For map, you must specify the keyType and valueType fields.
    • The keyType must, for the time being, be either 'text' or 'ascii'.
    • The valueType must be a scalar type.
  • For lists and sets, you must specify the valueType field.
    • The valueType must be a scalar type.
  • For vectors, you must specify the dimension field.
    • You may optionally provide a service field to enable vectorize.
    • Note that you still need to create a vector index on the column to actually use vector search.

See

  • LooseCreateTableColumnDefinition
  • StrictCreateTableColumnDefinition