Skip to main content

# Structure

Defines a new Table structure.

## Methods​

### constructor()​

→ (`tableDescription`? = Array<ColumnStructure>) → `this`

Parameters

Parameter | Type | Description
--- | --- | ---
`tableDescription` optional | Array<ColumnStructure> | An array holding a list of column structure objects to define columns with. You can get a `tableDescription` from a structure with the get() method, store it and load it again by creating a Structure with it in this constructor.

Returns

→ `this`

### get()​

→ () → Array<ColumnStructure>

Returns an array containing all defined columns in the ColumnStructure object.

With this you can save the structure and load it again by passing it to the constructor of a new Structure.

Returns

→ Array<ColumnStructure>

### drop()​

→ (`name` = String) → `this`

Drops (removes) a column from this structure.

Parameters

Parameter | Type | Description
--- | --- | ---
`name` | String | The column name to drop

Returns

→ `this`

### char()​

→ (`name` = String, `size`? = Number, `options`? = ConstraintOptions) → `this`

Adds a new column of data type 'char' to this structure

Parameters

Parameter | Type | Description
--- | --- | ---
`name` | String | Name of the column
`size` optional | Number | Maximum length of characters to store in this column. - Min: 0 - Max: 255 - Default: 1
`options` optional | ConstraintOptions | Additional constraint options

Returns

→ `this`

### varchar()​

→ (`name` = String, `size`? = Number, `options`? = ConstraintOptions) → `this`

Adds a new column of data type 'varchar' to this structure

Parameters

Parameter | Type | Description
--- | --- | ---
`name` | String | Name of the column
`size` optional | Number | Maximum length of characters to store in this column. - Min: 0 - Max: 255 - Default: 1
`options` optional | ConstraintOptions | Additional constraint options

Returns

→ `this`

### binary()​

→ (`name` = String, `size`? = Number, `options`? = ConstraintOptions) → `this`

Adds a new column of data type 'binary' to this structure

Parameters

Parameter | Type | Description
--- | --- | ---
`name` | String | Name of the column
`size` optional | Number | Maximum length of data. - Min: 1 - Default: 1
`options` optional | ConstraintOptions | Additional constraint options

Returns

→ `this`

### varbinary()​

→ (`name` = String, `size`? = Number, `options`? = ConstraintOptions) → `this`

Adds a new column of data type 'varbinary' to this structure

Parameters

Parameter | Type | Description
--- | --- | ---
`name` | String | Name of the column
`size` optional | Number | Maximum length of data. - Min: 0 - Default: 1
`options` optional | ConstraintOptions | Additional constraint options

Returns

→ `this`

### tinyblob()​

→ (`name` = String, `options`? = ConstraintOptions) → `this`

Adds a new column of data type 'tinyblob' to this structure

Parameters

Parameter | Type | Description
--- | --- | ---
`name` | String | Name of the column
`options` optional | ConstraintOptions | Additional constraint options

Returns

→ `this`

### tinytext()​

→ (`name` = String, `options`? = ConstraintOptions) → `this`

Adds a new column of data type 'tinytext' to this structure

Parameters

Parameter | Type | Description
--- | --- | ---
`name` | String | Name of the column
`options` optional | ConstraintOptions | Additional constraint options

Returns

→ `this`

### text()​

→ (`name` = String, `options`? = ConstraintOptions) → `this`

Adds a new column of data type 'text' to this structure

Parameters

Parameter | Type | Description
--- | --- | ---
`name` | String | Name of the column
`options` optional | ConstraintOptions | Additional constraint options

Returns

→ `this`

### blob()​

→ (`name` = String, `size`? = Number, `options`? = ConstraintOptions) → `this`

Adds a new column of data type 'blob' to this structure

Parameters

Parameter | Type | Description
--- | --- | ---
`name` | String | Name of the column
`size` optional | Number | Maximum length of characters to store in this column. - Min: 0 - Max: 65535 - Default: 65535
`options` optional | ConstraintOptions | Additional constraint options

Returns

→ `this`

### mediumtext()​

→ (`name` = String, `options`? = ConstraintOptions) → `this`

Adds a new column of data type 'mediumtext' to this structure

Parameters

Parameter | Type | Description
--- | --- | ---
`name` | String | Name of the column
`options` optional | ConstraintOptions | Additional constraint options

Returns

→ `this`

### longtext()​

→ (`name` = String, `options`? = ConstraintOptions) → `this`

Adds a new column of data type 'longtext' to this structure

Parameters

Parameter | Type | Description
--- | --- | ---
`name` | String | Name of the column
`options` optional | ConstraintOptions | Additional constraint options

Returns

→ `this`

### longblob()​

→ (`name` = String, `options`? = ConstraintOptions) → `this`

Adds a new column of data type 'longblob' to this structure

Parameters

Parameter | Type | Description
--- | --- | ---
`name` | String | Name of the column
`options` optional | ConstraintOptions | Additional constraint options

Returns

→ `this`

### enum()​

→ (`name` = String, `vals`? = Array<String>, `options`? = ConstraintOptions) → `this`

Adds a new column of data type 'enum' to this structure

Parameters

Parameter | Type | Description
--- | --- | ---
`name` | String | Name of the column
`vals` | Array<String> | Array of possible values for this column.
`options` optional | ConstraintOptions | Additional constraint options

Returns

→ `this`

### set()​

→ (`name` = String, `vals`? = Array<String>, `options`? = ConstraintOptions) → `this`

Adds a new column of data type 'enum' to this structure

Parameters

Parameter | Type | Description
--- | --- | ---
`name` | String | Name of the column
`vals` | Array<String> | Array of possible values for this column.
`options` optional | ConstraintOptions | Additional constraint options

Returns

→ `this`

### bit()​

→ (`name` = String, `size`? = Number, `options`? = ConstraintOptions) → `this`

Adds a new column of data type 'bit' to this structure

Parameters

Parameter | Type | Description
--- | --- | ---
`name` | String | Name of the column
`size` optional | Number | Maximum length of data. - Min: 1 - Max: 64 - Default: 1
`options` optional | ConstraintOptions | Additional constraint options

Returns

→ `this`

### tinyint()​

→ (`name` = String, `size`? = Number, `options`? = ConstraintOptions) → `this`

Adds a new column of data type 'tinyint' to this structure

Parameters

Parameter | Type | Description
--- | --- | ---
`name` | String | Name of the column
`size` optional | Number | Maximum length of data. - Min: 1 - Max: 255 - Default: 255
`options` optional | ConstraintOptions | Additional constraint options

Returns

→ `this`

### bool()​

→ (`name` = String, `options`? = ConstraintOptions) → `this`

Adds a new column of data type 'bool' to this structure

Parameters

Parameter | Type | Description
--- | --- | ---
`name` | String | Name of the column
`options` optional | ConstraintOptions | Additional constraint options

Returns

→ `this`

### smallint()​

→ (`name` = String, `size`? = Number, `options`? = ConstraintOptions) → `this`

Adds a new column of data type 'smallint' to this structure

Parameters

Parameter | Type | Description
--- | --- | ---
`name` | String | Name of the column
`size` optional | Number | Maximum length of data. - Min: 1 - Max: 255 - Default: 255
`options` optional | ConstraintOptions | Additional constraint options

Returns

→ `this`

### mediumint()​

→ (`name` = String, `size`? = Number, `options`? = ConstraintOptions) → `this`

Adds a new column of data type 'mediumint' to this structure

Parameters

Parameter | Type | Description
--- | --- | ---
`name` | String | Name of the column
`size` optional | Number | Maximum length of data. - Min: 1 - Max: 255 - Default: 255
`options` optional | ConstraintOptions | Additional constraint options

Returns

→ `this`

### int()​

→ (`name` = String, `size`? = Number, `options`? = ConstraintOptions) → `this`

Adds a new column of data type 'int' to this structure

Parameters

Parameter | Type | Description
--- | --- | ---
`name` | String | Name of the column
`size` optional | Number | Maximum length of data. - Min: 1 - Max: 255 - Default: 255
`options` optional | ConstraintOptions | Additional constraint options

Returns

→ `this`

### bigint()​

→ (`name` = String, `size`? = Number, `options`? = ConstraintOptions) → `this`

Adds a new column of data type 'bigint' to this structure

Parameters

Parameter | Type | Description
--- | --- | ---
`name` | String | Name of the column
`size` optional | Number | Maximum length of data. - Min: 1 - Max: 255 - Default: 255
`options` optional | ConstraintOptions | Additional constraint options

Returns

→ `this`

### float()​

→ (`name` = String, `p`? = Number, `options`? = ConstraintOptions) → `this`

Adds a new column of data type 'float' to this structure

Parameters

Parameter | Type | Description
--- | --- | ---
`name` | String | Name of the column
`p` optional | Number | Precision. - Min: 1 - Max: 53 - Default: 25
`options` optional | ConstraintOptions | Additional constraint options

Returns

→ `this`

### double()​

→ (`name` = String, `size`? = Number, `d`? = Number `options`? = ConstraintOptions) → `this`

Adds a new column of data type 'double' to this structure

Parameters

Parameter | Type | Description
--- | --- | ---
`name` | String | Name of the column
`size` optional | Number | Maximum length of data. - Min: 1 - Default: 16
`d` optional | Number | Double precision. - Min: 1 - Default: 8
`options` optional | ConstraintOptions | Additional constraint options

Returns

→ `this`

### decimal()​

→ (`name` = String, `size`? = Number, `d`? = Number `options`? = ConstraintOptions) → `this`

Adds a new column of data type 'decimal' to this structure

Parameters

Parameter | Type | Description
--- | --- | ---
`name` | String | Name of the column
`size` optional | Number | Maximum length of data. - Min: 1 - Default: 16
`d` optional | Number | Double precision. - Min: 1 - Default: 8
`options` optional | ConstraintOptions | Additional constraint options

Returns

→ `this`

### date()​

→ (`name` = String,`options`? = ConstraintOptions) → `this`

Adds a new column of data type 'date' to this structure

Parameters

Parameter | Type | Description
--- | --- | ---
`name` | String | Name of the column
`options` optional | ConstraintOptions | Additional constraint options

Returns

→ `this`

### datetime()​

→ (`name` = String, `fsp`? = Number, `options`? = ConstraintOptions) → `this`

Adds a new column of data type 'datetime' to this structure

Parameters

Parameter | Type | Description
--- | --- | ---
`name` | String | Name of the column
`fsp` optional | Number | Fractional second precision. - Min: 0 - Max: 6 - Default: 0
`options` optional | ConstraintOptions | Additional constraint options

Returns

→ `this`

### timestamp()​

→ (`name` = String, `fsp`? = Number, `options`? = ConstraintOptions) → `this`

Adds a new column of data type 'timestamp' to this structure

Parameters

Parameter | Type | Description
--- | --- | ---
`name` | String | Name of the column
`fsp` optional | Number | Fractional second precision. - Min: 0 - Max: 6 - Default: 0
`options` optional | ConstraintOptions | Additional constraint options

Returns

→ `this`

### time()​

→ (`name` = String, `fsp`? = Number, `options`? = ConstraintOptions) → `this`

Adds a new column of data type 'time' to this structure

Parameters

Parameter | Type | Description
--- | --- | ---
`name` | String | Name of the column
`fsp` optional | Number | Fractional second precision. - Min: 0 - Max: 6 - Default: 0
`options` optional | ConstraintOptions | Additional constraint options

Returns

→ `this`

### year()​

→ (`name` = String, `options`? = ConstraintOptions) → `this`

Adds a new column of data type 'year' to this structure

Parameters

Parameter | Type | Description
--- | --- | ---
`name` | String | Name of the column
`options` optional | ConstraintOptions | Additional constraint options

Returns

→ `this`