create method

TableDefinition create(
  1. String tableName,
  2. dynamic callback(
    1. Schema
    ), [
  3. bool ifNotExists = false
])

Implementation

TableDefinition create(String tableName, Function(Schema) callback,
    [bool ifNotExists = false]) {
  _schemaBuilder.reset();
  _schemaBuilder.setTableName(tableName);

  Future<void> createFunction() async {
    callback(_schemaBuilder);

    String sql = _schemaBuilder.generateCreateTableSql(tableName,
        ifNotExists: ifNotExists);

    if (_adapter != null && _adapter.driverName == 'pgsql') {
      final postgresAdapter = _adapter as dynamic;
      if (postgresAdapter.executeStatements != null) {
        await postgresAdapter.executeStatements(sql,
            (List<String> statements) async {
          for (String statement in statements) {
            await _connection.connection!.execute(statement);
          }
        });
        return;
      }
    }

    if (_adapter != null) {
      sql = _adapter.adaptQuery(sql);
    }
    try {
      await _connection.connection!.execute(sql);
    } on QueryException catch (e) {
      stderr.writeln(
        'Error executing statement: $sql\nError: ${e.cause}',
      );
      exit(0);
    }
  }

  return TableDefinition(tableName, createFunction,
      connection: _connection, adapter: _adapter);
}