escapeIfNeeded function Null safety

String escapeIfNeeded(
  1. String s,
  2. [SqlDialect dialect = SqlDialect.sqlite]
)

Escapes s by wrapping it in backticks if it's an sqlite keyword.

Implementation

String escapeIfNeeded(String s, [SqlDialect dialect = SqlDialect.sqlite]) {
  final inUpperCase = s.toUpperCase();
  var isKeyword = baseKeywords.contains(inUpperCase);

  if (dialect == SqlDialect.postgres) {
    isKeyword |= additionalPostgresKeywords.contains(inUpperCase);
  }

  if (isKeyword || s.contains(_whitespace)) return '"$s"';
  return s;
}