mirror of https://github.com/AMT-Cheif/drift.git
150 lines
1.9 KiB
Dart
150 lines
1.9 KiB
Dart
/// Provides utilities around sql keywords, like optional escaping etc.
|
|
library moor.sqlite_keywords;
|
|
|
|
// https://www.sqlite.org/lang_keywords.html
|
|
const sqliteKeywords = {
|
|
'ABORT',
|
|
'ACTION',
|
|
'ADD',
|
|
'AFTER',
|
|
'ALL',
|
|
'ALTER',
|
|
'ANALYZE',
|
|
'AND',
|
|
'AS',
|
|
'ASC',
|
|
'ATTACH',
|
|
'AUTOINCREMENT',
|
|
'BEFORE',
|
|
'BEGIN',
|
|
'BETWEEN',
|
|
'BY',
|
|
'CASCADE',
|
|
'CASE',
|
|
'CAST',
|
|
'CHECK',
|
|
'COLLATE',
|
|
'COLUMN',
|
|
'COMMIT',
|
|
'CONFLICT',
|
|
'CONSTRAINT',
|
|
'CREATE',
|
|
'CROSS',
|
|
'CURRENT',
|
|
'CURRENT_DATE',
|
|
'CURRENT_TIME',
|
|
'CURRENT_TIMESTAMP',
|
|
'DATABASE',
|
|
'DEFAULT',
|
|
'DEFERRABLE',
|
|
'DEFERRED',
|
|
'DELETE',
|
|
'DESC',
|
|
'DETACH',
|
|
'DISTINCT',
|
|
'DO',
|
|
'DROP',
|
|
'EACH',
|
|
'ELSE',
|
|
'END',
|
|
'ESCAPE',
|
|
'EXCEPT',
|
|
'EXCLUSIVE',
|
|
'EXISTS',
|
|
'EXPLAIN',
|
|
'FAIL',
|
|
'FILTER',
|
|
'FOLLOWING',
|
|
'FOR',
|
|
'FOREIGN',
|
|
'FROM',
|
|
'FULL',
|
|
'GLOB',
|
|
'GROUP',
|
|
'HAVING',
|
|
'IF',
|
|
'IGNORE',
|
|
'IMMEDIATE',
|
|
'IN',
|
|
'INDEX',
|
|
'INDEXED',
|
|
'INITIALLY',
|
|
'INNER',
|
|
'INSERT',
|
|
'INSTEAD',
|
|
'INTERSECT',
|
|
'INTO',
|
|
'IS',
|
|
'ISNULL',
|
|
'JOIN',
|
|
'KEY',
|
|
'LEFT',
|
|
'LIKE',
|
|
'LIMIT',
|
|
'MATCH',
|
|
'NATURAL',
|
|
'NO',
|
|
'NOT',
|
|
'NOTHING',
|
|
'NOTNULL',
|
|
'NULL',
|
|
'OF',
|
|
'OFFSET',
|
|
'ON',
|
|
'OR',
|
|
'ORDER',
|
|
'OUTER',
|
|
'OVER',
|
|
'PARTITION',
|
|
'PLAN',
|
|
'PRAGMA',
|
|
'PRECEDING',
|
|
'PRIMARY',
|
|
'QUERY',
|
|
'RAISE',
|
|
'RANGE',
|
|
'RECURSIVE',
|
|
'REFERENCES',
|
|
'REGEXP',
|
|
'REINDEX',
|
|
'RELEASE',
|
|
'RENAME',
|
|
'REPLACE',
|
|
'RESTRICT',
|
|
'RIGHT',
|
|
'ROLLBACK',
|
|
'ROW',
|
|
'ROWS',
|
|
'SAVEPOINT',
|
|
'SELECT',
|
|
'SET',
|
|
'TABLE',
|
|
'TEMP',
|
|
'TEMPORARY',
|
|
'THEN',
|
|
'TO',
|
|
'TRANSACTION',
|
|
'TRIGGER',
|
|
'UNBOUNDED',
|
|
'UNION',
|
|
'UNIQUE',
|
|
'UPDATE',
|
|
'USING',
|
|
'VACUUM',
|
|
'VALUES',
|
|
'VIEW',
|
|
'VIRTUAL',
|
|
'WHEN',
|
|
'WHERE',
|
|
'WINDOW',
|
|
'WITH',
|
|
'WITHOUT'
|
|
};
|
|
|
|
bool isSqliteKeyword(String s) => sqliteKeywords.contains(s.toUpperCase());
|
|
|
|
String escapeIfNeeded(String s) {
|
|
if (isSqliteKeyword(s)) return '`$s`';
|
|
return s;
|
|
}
|