Type Definitions

ColumnConfig

Type:
  • Object
Properties
NameTypeAttributesDefaultDescription
typestring

Data type of the column (e.g., 'VARCHAR(100)', 'INT', 'TIMESTAMP').

primaryKeyboolean<optional>
false

Indicates if the column is a primary key.

nullableboolean<optional>
true

Indicates if the column allows NULL values.

default*<optional>

Default value for the column.

generatedstring<optional>

Expression for a generated column (e.g., 'GENERATED ALWAYS AS (expression) STORED').

uniqueboolean<optional>
false

Indicates if the column has a unique constraint.

referencesstring<optional>

References table and column for a foreign key (e.g., 'other_table(other_column)').

onDeletestring<optional>

Action to take on delete (e.g., 'CASCADE', 'SET NULL').

onUpdatestring<optional>

Action to take on update (e.g., 'CASCADE', 'RESTRICT').

checkstring<optional>

CHECK constraint condition.

collatestring<optional>

Collation to use for the column.

commentstring<optional>

Comment for the column.

constraintstring<optional>

Additional constraints for the column.

indexstring<optional>

Defines an index on the column.

ConstraintsConfig

An object representing additional constraints on the table. Each key is the constraint name, and the value is the constraint definition.

Type:
  • Object.<string, string>
Example
const schema = {
  tableName: 'vendor_addresses',
  columns: {
    vendor_id: { type: 'uuid' },
    address_id: { type: 'uuid' },
  },
  constraints: {
    pk_vendor_address: 'PRIMARY KEY (vendor_id, address_id)',
    fk_vendor_id: 'FOREIGN KEY (vendor_id) REFERENCES vendors(id) ON DELETE CASCADE',
    fk_address_id: 'FOREIGN KEY (address_id) REFERENCES addresses(id) ON DELETE CASCADE',
  },
};

IndexConfig

Type:
  • Object
Properties
NameTypeAttributesDefaultDescription
uniqueboolean<optional>
false

Indicates if the index is unique.

configstring

Configuration for the index (e.g., 'table(column)').

Schema

Type:
  • Object
Properties
NameTypeAttributesDefaultDescription
tableNamestring

The name of the table.

dbSchemastring<optional>
'public'

The schema of the table.

timeStampsboolean<optional>
true

Indicates if the table should include timestamp columns (created_at, created_by, updated_at, updated_by).

columnsObject.<string, ColumnConfig>

Definitions for the columns in the table.

constraintsConstraintsConfig<optional>

Additional constraints on the table.

indexesObject.<string, IndexConfig><optional>

Definitions for the indexes on the table.