toSQL method

  1. @override
String toSQL()
override

Generates the SQL for this custom field with optional alias.

Returns the field SQL with "AS alias" if an alias is provided, otherwise just the field SQL.

Example:

QSelectCustom(QSelect('name'), as: 'full_name').toSQL(); // "`name` AS `full_name`"
QSelectCustom(QMath('COUNT(*)')).toSQL(); // "COUNT(*)"

Implementation

@override
String toSQL() {
  return as.isNotEmpty
      ? '${field.toSQL()} AS ${QField(as).toSQL()}'
      : field.toSQL();
}