Column Types
Documentation below reflects SQL adapters.
When defining schema at Collection.schema, or passing it to Schema.createTable(), we define the type of the field/column.
There are various supported column types as of this moment.
Available Types
- increments
- integer
- bigInteger
- text
textType:mediumtextorlongtext
- string
length
- float
precisionscale
- decimal
precisionscale
- boolean
- date
- dateTime
- time
- timestamp
standard
- binary
length
- enum
values: array of values
- json
- uuid
Child items represent the additional keys that can be passed to schema for them.
Usage
db.schema()
.createTable('posts', {
id: {
type: 'uuid'
},
title: {
type: 'string'
}
});
Options
Some columns can also have additional information about them.
For example, string type can also have a specified length:
db.schema()
.createTable('posts', {
title: {
type: 'string',
length: 100
}
});
Other common options include:
primary: booleanunique: booleannullable: booleandefault: default valueunsigned: booleancomment: comment for the column
Usage
db.schema()
.createTable('posts', {
title: {
type: 'string',
length: 100,
nullable: true
}
});