escapeIfNeeded function

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 || _notInKeyword.hasMatch(s)) return '"$s"';
  return s;
}