mysqlTable function. Tables are the foundation of your database schema.
Table Definition
mysqlTable()
Defines a MySQL table with columns and constraints.string
required
The name of the table in the database.
object | function
required
Column definitions. Can be an object of column builders or a function that receives column type helpers.
function
Function to define indexes, foreign keys, and other constraints. Should return an array of constraint builders.
Examples
mysqlTableCreator()
Creates a custom table creator with a name transformation function. Useful for adding prefixes or custom naming conventions.function
required
Function that transforms table names. Receives the provided name and returns the actual database table name.
Examples
Schema Organization
mysqlTableWithSchema()
Defines a table within a specific MySQL schema/database.string
required
The table name.
object
required
Column definitions.
function
required
Constraints and indexes configuration.
string
required
The schema/database name.
string
Base name for internal reference. Defaults to
name.Examples
Table Constraints
Constraints are defined in the third parameter (extraConfig) ofmysqlTable.
Indexes
Primary Keys
Foreign Keys
Unique Constraints
Check Constraints
Type Helpers
MySqlTable
The base table class. All tables defined withmysqlTable() are instances of this class.
InferModel
Infer TypeScript types from table definitions.Table Configuration
MySqlTableExtraConfigValue
Union type of all possible table configuration values.Best Practices
Naming conventions: Choose consistent naming for tables (e.g., plural form like
users, posts) and stick with it throughout your schema.