2015-12-04 00:28:18 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
var sqlQueryMayWriteRegex = new RegExp('\\b(alter|insert|update|delete|create|drop|reindex|truncate|refresh)\\b', 'i');
|
2015-12-04 00:28:18 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This is a fuzzy check, the return could be true even if the query doesn't really write anything. But you can be
|
|
|
|
* pretty sure of a false return.
|
|
|
|
*
|
|
|
|
* @param sql The SQL statement to check against
|
|
|
|
* @returns {boolean} Return true of the given query may write to the database
|
|
|
|
*/
|
2019-12-24 01:19:08 +08:00
|
|
|
module.exports = function queryMayWrite (sql) {
|
2015-12-04 00:28:18 +08:00
|
|
|
return sqlQueryMayWriteRegex.test(sql);
|
2015-12-04 01:45:12 +08:00
|
|
|
};
|