write method

void write(
  1. SqlQuery query
)

Implementation

void write(SqlQuery query) {
  // Note that writing queries can have a result set if they use a RETURNING
  // clause.
  final resultSet = query.resultSet;
  if (resultSet?.needsOwnClass == true) {
    final resultSetScope = scope.findScopeOfLevel(DartScope.library);
    ResultSetWriter(query, resultSetScope).write();
  }

  // The new sql code generation generates query code from the parsed AST,
  // which eliminates unnecessary whitespace and comments. These can sometimes
  // have a semantic meaning though, for instance when they're used in
  // columns. So, we transform the query to add an explicit alias to every
  // column!
  // We do this transformation so late because it shouldn't have an impact on
  // analysis, Dart getter names stay the same.
  if (resultSet != null && options.newSqlCodeGeneration) {
    _transformer = ExplicitAliasTransformer();
    _transformer.rewrite(query.root!);

    final nested = query is SqlSelectQuery ? query.nestedContainer : null;
    if (nested != null) {
      addHelperNodes(nested);
    }
  }

  if (query is SqlSelectQuery) {
    _writeSelect(query);
  } else if (query is UpdatingQuery) {
    if (resultSet != null) {
      _writeUpdatingQueryWithReturning(query);
    } else {
      _writeUpdatingQuery(query);
    }
  }
}