primary key

The primary key uniquely identifies each row. By default, Sedentary adds an implicit id attribute (INT, auto-increment). Use ModelOptions.primaryKey to specify a custom primary key, or ModelOptions.parent to inherit it.

ModelOptions

interface ModelOptions {
    indexes?: IndexesDefinition;
    int8id?: boolean;
    parent?: Model;
    primaryKey?: string;
    sync?: boolean;
    tableName?: string;
}

Specifies the options for the Model.

ModelOptions.indexes

  • default: {}

Defines the indexes of the Model. See IndexesDefinition for details.

ModelOptions.int8id

  • default: false

If true, the implicit id attribute used as primary key is of type INT8, see data types for details.

Note

This option conflicts with ModelOptions.parent and ModelOptions.primaryKey ones.

ModelOptions.parent

  • default: undefined

If provided, defines the parent of the Model. This reflects both on classes hierarchy at JavaScript level and on tables hierarchy at database level. The primary key is inherited as well: neither an implicit id attribute is added nor can be specified through ModelOptions.primaryKey option.

Warning

Not all the database engine specialized packages may support this option.

Note

This option conflicts with ModelOptions.int8id and ModelOptions.primaryKey ones.

ModelOptions.primaryKey

  • default: undefined

The value must be the name of an attribute. If provided, defines the primary key of the Model. The implicit id attribute is not added to the Model.

Note

This option conflicts with ModelOptions.int8id and ModelOptions.parent ones.

ModelOptions.sync

If false, Sedentary does not sync the table associated to the Model, it simply checks if the Model is compliant with the table at database level.

ModelOptions.tableName

  • default: same as the model name

Overrides the name of the table at database level. By default, the table name equals the model name.