Type Definitions
ColumnConfig
- Object
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
type | string | Data type of the column (e.g., 'VARCHAR(100)', 'INT', 'TIMESTAMP'). | ||
primaryKey | boolean | <optional> | false | Indicates if the column is a primary key. |
nullable | boolean | <optional> | true | Indicates if the column allows NULL values. |
default | * | <optional> | Default value for the column. | |
generated | string | <optional> | Expression for a generated column (e.g., 'GENERATED ALWAYS AS (expression) STORED'). | |
unique | boolean | <optional> | false | Indicates if the column has a unique constraint. |
references | string | <optional> | References table and column for a foreign key (e.g., 'other_table(other_column)'). | |
onDelete | string | <optional> | Action to take on delete (e.g., 'CASCADE', 'SET NULL'). | |
onUpdate | string | <optional> | Action to take on update (e.g., 'CASCADE', 'RESTRICT'). | |
check | string | <optional> | CHECK constraint condition. | |
collate | string | <optional> | Collation to use for the column. | |
comment | string | <optional> | Comment for the column. | |
constraint | string | <optional> | Additional constraints for the column. | |
index | string | <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.
- Object.<string, string>
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
- Object
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
unique | boolean | <optional> | false | Indicates if the index is unique. |
config | string | Configuration for the index (e.g., 'table(column)'). |
Schema
- Object
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
tableName | string | The name of the table. | ||
dbSchema | string | <optional> | 'public' | The schema of the table. |
timeStamps | boolean | <optional> | true | Indicates if the table should include timestamp columns (created_at, created_by, updated_at, updated_by). |
columns | Object.<string, ColumnConfig> | Definitions for the columns in the table. | ||
constraints | ConstraintsConfig | <optional> | Additional constraints on the table. | |
indexes | Object.<string, IndexConfig> | <optional> | Definitions for the indexes on the table. |