composeFind function

String composeFind(
  1. Find find
)

Implementation

String composeFind(final Find find) {
  final ImmutableFindStatement info = find.asImmutable;
  final sb = new StringBuffer();
  sb.write('SELECT ');

  if (info.selects.length == 0) {
    sb.write('* ');
  } else {
    sb.write(info.selects.map(composeSelColumn).toList().join(', '));
  }

  sb.write(' FROM ');
  sb.write(composeTableName(info.from));

  for (JoinedTable tab in info.joins) {
    sb.write(' ');
    sb.write(composeJoinedTable(tab));
  }

  if (info.where.length != 0) {
    sb.write(' WHERE ');
    sb.write(composeExpression(info.where));
  }

  if (info.groupBy.length != 0) {
    sb.write(' GROUP BY ');
    sb.write(info.groupBy.join(', '));
  }

  if (info.orderBy.length != 0) {
    sb.write(' ORDER BY ');
    sb.write(info.orderBy.map(composeOrderBy).join(', '));
  }

  if (info.limit is int) {
    sb.write(' LIMIT ');
    sb.write(info.limit);
  }

  if (info.offset is int) {
    sb.write(' OFFSET ');
    sb.write(info.offset);
  }

  sb.write(';');

  return sb.toString();
}