MySQL Driver
MySQL migration support with inline ENUM columns, btree/fulltext/spatial indexes, and InnoDB-aware type handling
Capabilities
| Feature | Supported |
|---|---|
| Native enums | Yes (inline ENUM column type) |
| Native arrays | No (stored as JSON) |
| Index types | btree, fulltext, spatial |
| Transactions | Limited — DDL statements implicitly commit |
Type Mappings
| VibORM Scalar | MySQL Type |
|---|---|
string() |
TEXT |
int() |
INT |
bigint() |
BIGINT |
float() |
DOUBLE |
decimal() |
DECIMAL(65,30) |
boolean() |
TINYINT(1) |
datetime() |
DATETIME(3) |
date() |
DATE |
time() |
TIME(3) |
json() |
JSON |
blob() |
BLOB |
enumScalar() |
Inline ENUM('a', 'b', ...) |
| Array scalars | JSON |
DATETIME(3) and TIME(3) preserve JavaScript Date millisecond precision.
Portable String Collation
VibORM’s MySQL adapter targets MySQL 8.0+. New tables use
utf8mb4_0900_bin. Its binary, no-pad comparison keeps case,
accents, and trailing spaces distinct for primary keys and unique constraints,
matching PostgreSQL and SQLite-family behavior.
Existing MySQL tables are not converted automatically because VibORM’s schema snapshot does not track table collation. Apply an explicit migration for each existing table that participates in portable string comparisons:
ALTER TABLE `users`
CONVERT TO CHARACTER SET utf8mb4
COLLATE utf8mb4_0900_bin;
This rebuilds character columns and their indexes and may lock or copy a large table. Review the database’s online-DDL plan and deploy the migration deliberately; a code upgrade alone does not change existing schema semantics.
Auto-Increment
AUTO_INCREMENT requires an integer column type (TINYINT, SMALLINT, MEDIUMINT, INT, BIGINT); the driver rejects it on anything else:
const User = model("users", {
id: int().primaryKey().autoIncrement(),
});
Generates:
CREATE TABLE `users` (
`id` INT AUTO_INCREMENT PRIMARY KEY
);
Enums
MySQL has no standalone enum type — the ENUM is part of the column definition:
const User = model("users", {
status: enumScalar(["active", "inactive", "pending"]),
});
Generates:
CREATE TABLE `users` (
`status` ENUM('active', 'inactive', 'pending') NOT NULL
);
Changing an enum’s values therefore issues a MODIFY COLUMN for every column using it.
Index Types
The driver generates and introspects btree (default), FULLTEXT, and SPATIAL indexes. InnoDB does not support user-defined hash indexes. See Index Options for declaring indexes on models.
Indexed TEXT Columns
InnoDB can’t index a TEXT column without an explicit key length. When a string() column participates in a primary key, unique constraint, index, or foreign key, the driver maps it to VARCHAR(191) instead (191 × 4 bytes fits the 767-byte InnoDB key limit).
Column Defaults
MySQL doesn’t allow DEFAULT values on TEXT, BLOB, JSON, or spatial columns; the driver omits defaults for those types.
Limitations
| Limitation | Behavior |
|---|---|
| DDL in transactions | Statements implicitly commit — a failed migration can leave earlier statements applied |
| Native arrays | Stored as JSON |
| Hash indexes | Not supported by InnoDB |