toSQL method

  1. @override
String toSQL()
override

Generates the SQL for this field with optional alias.

Returns the field name (properly quoted) with "AS alias" if an alias is provided.

Example:

QSelect('name').toSQL(); // "`name`"
QSelect('email', as: 'user_email').toSQL(); // "`email` AS `user_email`"

Implementation

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