create method

  1. @override
void create(
  1. String tableName,
  2. void callback(
    1. Blueprint
    )
)
override

Creates a new table with the given tableName and callback.

The callback receives a Blueprint to define the table columns and constraints.

Implementation

@override
void create(String tableName, void Function(Blueprint) callback) {
  final blueprint = Blueprint(tableName);
  callback(blueprint);

  final columnSQLs = blueprint.columns.map(_columnToSQL).toList();
  final constraints = _generateConstraints(blueprint, tableName);
  final fullSQL = [
    ...columnSQLs,
    ...constraints,
  ].join(', ');

  _queries.add('CREATE TABLE `$tableName` ($fullSQL);');
}