wrap method

String wrap(
  1. Object identifier
)

Quotes table.column, column as alias, table.* or *. Invalid characters throw instead of being interpolated (never trust input).

Implementation

String wrap(Object identifier) {
  if (identifier is RawExpression) {
    return identifier.sql;
  }
  final text = '$identifier';
  if (text.contains('->') && !_alias.hasMatch(text)) {
    return _wrapJson(text);
  }
  final alias = _alias.firstMatch(text);
  if (alias != null) {
    return '${wrap(alias.group(1)!)} AS ${_quote(alias.group(2)!.trim())}';
  }
  return text
      .split('.')
      .map((part) => part == '*' ? '*' : _quote(part))
      .join('.');
}