Type alias CreateTablePrimaryKeyDefinition<PKCols>

CreateTablePrimaryKeyDefinition<PKCols>: PKCols | FullCreateTablePrimaryKeyDefinition<PKCols>
Overview

Represents the syntax for defining the primary key of a table through the bespoke Data API schema definition syntax, in which there are two branching ways to define the primary key.

Type Parameters

  • PKCols extends string

Example

await db.createTable('my_table', {
definition: {
columns: ...,
primaryKey: {
partitionBy: ['pt_key'],
partitionSort: { cl_key: 1 },
},
},
});
The shorthand definition

If your table only has a single partition key, then you can define the partition key as simply

primaryKey: 'pt_key',

This is equivalent to the following full definition:

primaryKey: {
partitionBy: ['pt_key'],
partitionSort: {}, // note that this field is also optional if it's empty
}
The full definition

If your table has multiple columns in its primary key, you may use the full primary key definition syntax to express that:

primaryKey: {
partitionBy: ['pt_key1', 'pt_key2'],
partitionSort: { cl_key1: 1, cl_key2: -1 },
}

A sort of 1 on the clustering column means ascending, and a sort of -1 means descending.

Note that, if you don't have any clustering keys (partition sorts), you can omit the partitionSort field entirely:

primaryKey: {
partitionBy: ['pt_key1', 'pt_key2'],
}

See

FullCreateTablePrimaryKeyDefinition