toSQL<T extends SqlType> method

  1. @override
String toSQL<T extends SqlType>()
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<T extends SqlType>() {
  return as.isNotEmpty
      ? '${field.toSQL<T>()} AS ${QField(as).toSQL<T>()}'
      : field.toSQL<T>();
}