MTable class

Represents a MySQL table definition with fields, foreign keys, and table options.

This class implements the SQL interface and provides functionality to generate CREATE TABLE statements for MySQL databases.

Example:

final table = MTable(
  name: 'users',
  fields: [
    MFieldInt(name: 'id', isPrimaryKey: true, isAutoIncrement: true),
    MFieldVarchar(name: 'name', length: 100),
    MFieldVarchar(name: 'email', length: 255),
  ],
);
print(table.toSQL()); // Generates CREATE TABLE statement
Implemented types
Available extensions

Constructors

MTable.new({required String name, required List<MField> fields, List<ForeignKey> foreignKeys = const [], String charset = 'utf8mb4', String collation = 'utf8mb4_unicode_ci'})
Creates a new MySQL table definition.

Properties

charset String
Character set for the table (default: utf8mb4)
getter/setter pair
collation String
Collation for the table (default: utf8mb4_unicode_ci)
getter/setter pair
engine String
Storage engine for the table (default: InnoDB)
getter/setter pair
fields List<MField>
List of fields/columns in the table
getter/setter pair
foreignKeys List<ForeignKey>
List of foreign key constraints for the table
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
name String
The name of the table
getter/setter pair
qName QField
A QField representation of the table name for query building
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

allSelectFields({String alias = '', String prefix = ''}) List<QSelect>
Generates a list of QSelect objects for all fields in the table.
createForeignKeys(MySQLConnection conn) Future<MySqlResult?>

Available on MTable, provided by the MySqlTable extension

Creates foreign key constraints for the table.
createJoin(On on, {String as = ''}) Join
Creates a Join object for this table with the specified join condition.
createLeftJoin(On on, {String as = ''}) LeftJoin
Creates a LeftJoin object for this table with the specified join condition.
createRightJoin(On on, {String as = ''}) RightJoin
Creates a RightJoin object for this table with the specified join condition.
createTable(MySQLConnection conn) Future<MySqlResult>

Available on MTable, provided by the MySqlTable extension

Creates the table in the MySQL database.
delete(MySQLConnection conn, Sqler query) Future<MySqlResult>

Available on MTable, provided by the MySqlTable extension

Executes a DELETE query on the table.
dropTable(MySQLConnection conn) Future<MySqlResult>

Available on MTable, provided by the MySqlTable extension

Drops the table from the MySQL database.
execute(MySQLConnection conn, String sql) Future<MySqlResult>

Available on MTable, provided by the MySqlTable extension

Executes a SQL query against the MySQL database connection.
existsTable(MySQLConnection conn) Future<bool>

Available on MTable, provided by the MySqlTable extension

Checks if the table exists in the MySQL database.
formValidate(Map<String, Object?> data) Future<Map<String, List<String>>>
Validates the provided data against the table's fields. Returns a map of field names to lists of validation error messages. @data are input data to validate against the table's fields. @returns a map of field names to lists of validation error messages.
formValidateUI(Map<String, Object?> data) Future<FormResult>

Available on MTable, provided by the MySqlTable extension

Validates form data against the table's field definitions.
getFieldsAs([String from = '', String newAlias = '']) List<QSelectField>
Generates a list of QSelectField objects for SELECT queries with aliases.
getFieldsAs(String from, String as) List<QSelectField>

Available on MTable, provided by the MySqlTable extension

Gets table fields as select fields with optional table prefixes and aliases.
insert(MySQLConnection conn, Map<String, QVar> data) Future<MySqlResult>

Available on MTable, provided by the MySqlTable extension

Inserts a single record into the table.
insertMany(MySQLConnection conn, List<Map<String, QVar>> data) Future<MySqlResult>

Available on MTable, provided by the MySqlTable extension

Inserts multiple records into the table.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
select(MySQLConnection conn, Sqler query) Future<MySqlResult>

Available on MTable, provided by the MySqlTable extension

Executes a SELECT query on the table.
toSQL() String
Generates the SQL CREATE TABLE statement for this table.
override
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited