MySqlTable extension

Extension for MTable that provides MySQL-specific database operations. This extension adds functionality for table management, data manipulation, and form validation specifically for MySQL databases. It includes methods for creating, dropping, and querying tables, as well as handling foreign key constraints and form validation.

on

Methods

createForeignKeys(DatabaseDriver conn) Future<SqlDatabaseResult?>

Available on MTable, provided by the MySqlTable extension

Creates foreign key constraints for the table. Generates and executes ALTER TABLE statements to add foreign key constraints defined in the table's foreign keys collection. Each constraint is given a unique name using the current timestamp. Parameters:
createTable(DatabaseDriver conn) Future<SqlDatabaseResult>

Available on MTable, provided by the MySqlTable extension

Creates the table in the MySQL database. Generates and executes a CREATE TABLE SQL statement based on the table definition. The SQL is generated using the table's toSQL() method. Parameters:
delete(DatabaseDriver conn, Sqler query) Future<SqlDatabaseResult>

Available on MTable, provided by the MySqlTable extension

Executes a DELETE query on the table. Executes the provided query to delete records from the table. The method includes a safety check to ensure the query contains a DELETE statement. Parameters:
dropTable(DatabaseDriver conn) Future<SqlDatabaseResult>

Available on MTable, provided by the MySqlTable extension

Drops the table from the MySQL database. Executes a DROP TABLE IF EXISTS statement to safely remove the table from the database. The IF EXISTS clause prevents errors if the table doesn't exist. Parameters:
execute(DatabaseDriver conn, Sqler sqler) Future<SqlDatabaseResult>

Available on MTable, provided by the MySqlTable extension

Executes a SQL query against the MySQL database connection. This is a low-level method that executes raw SQL queries. It handles exceptions and wraps results in a MySqlResult object for consistent error handling across the application. Parameters:
existsTable(DatabaseDriver conn) Future<bool>

Available on MTable, provided by the MySqlTable extension

Checks if the table exists in the MySQL database. This method queries the MySQL information schema to determine if a table with the current name exists in the database. Parameters:
formValidateUI(Map<String, Object?> data) Future<FormResult>

Available on MTable, provided by the MySqlTable extension

Validates form data against the table's field definitions. This method performs comprehensive validation of input data based on the validators defined for each table field. It creates a form validator instance and processes all field validations. Parameters:
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. This method transforms table fields into QSelectField objects suitable for SQL SELECT queries. It handles table prefixes and field aliases. Parameters:
insert(DatabaseDriver conn, Map<String, QVar> data) Future<SqlDatabaseResult>

Available on MTable, provided by the MySqlTable extension

Inserts a single record into the table. Convenience method that wraps insertMany for single record insertion. This is useful when you only need to insert one row. Parameters:
insertMany(DatabaseDriver conn, List<Map<String, QVar>> data) Future<SqlDatabaseResult>

Available on MTable, provided by the MySqlTable extension

Inserts multiple records into the table. Executes a bulk INSERT statement to add multiple rows to the table in a single database operation, which is more efficient than individual inserts. Parameters:
select(DatabaseDriver conn, Sqler query) Future<SqlDatabaseResult>

Available on MTable, provided by the MySqlTable extension

Executes a SELECT query on the table. Executes the provided query to retrieve data from the table. The query should be constructed using the Sqler query builder. Parameters: