aboutsummaryrefslogtreecommitdiff
path: root/node_modules/mysql2/lib/parsers/parser_cache.js
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.h.kronqvist@gmail.com>2022-03-05 19:02:27 +0200
committerJoel Kronqvist <joel.h.kronqvist@gmail.com>2022-03-05 19:02:27 +0200
commit5d309ff52cd399a6b71968a6b9a70c8ac0b98981 (patch)
tree360f7eb50f956e2367ef38fa1fc6ac7ac5258042 /node_modules/mysql2/lib/parsers/parser_cache.js
parentb500a50f1b97d93c98b36ed9a980f8188d648147 (diff)
downloadLYLLRuoka-5d309ff52cd399a6b71968a6b9a70c8ac0b98981.tar.gz
LYLLRuoka-5d309ff52cd399a6b71968a6b9a70c8ac0b98981.zip
Added node_modules for the updating to work properly.
Diffstat (limited to 'node_modules/mysql2/lib/parsers/parser_cache.js')
-rw-r--r--node_modules/mysql2/lib/parsers/parser_cache.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/node_modules/mysql2/lib/parsers/parser_cache.js b/node_modules/mysql2/lib/parsers/parser_cache.js
new file mode 100644
index 0000000..509b5c6
--- /dev/null
+++ b/node_modules/mysql2/lib/parsers/parser_cache.js
@@ -0,0 +1,53 @@
+'use strict';
+
+const LRU = require('lru-cache');
+
+const parserCache = new LRU({
+ max: 15000
+});
+
+function keyFromFields(type, fields, options, config) {
+ let res =
+ `${type}` +
+ `/${typeof options.nestTables}` +
+ `/${options.nestTables}` +
+ `/${options.rowsAsArray}` +
+ `/${options.supportBigNumbers || config.supportBigNumbers}` +
+ `/${options.bigNumberStrings || config.bigNumberStrings}` +
+ `/${typeof options.typeCast}` +
+ `/${options.timezone || config.timezone}` +
+ `/${options.decimalNumbers}` +
+ `/${options.dateStrings}`;
+ for (let i = 0; i < fields.length; ++i) {
+ const field = fields[i];
+ res += `/${field.name}:${field.columnType}:${field.length}:${field.schema}:${field.table}:${field.flags}:${field.characterSet}`;
+ }
+ return res;
+}
+
+function getParser(type, fields, options, config, compiler) {
+ const key = keyFromFields(type, fields, options, config);
+ let parser = parserCache.get(key);
+
+ if (parser) {
+ return parser;
+ }
+
+ parser = compiler(fields, options, config);
+ parserCache.set(key, parser);
+ return parser;
+}
+
+function setMaxCache(max) {
+ parserCache.max = max;
+}
+
+function clearCache() {
+ parserCache.reset();
+}
+
+module.exports = {
+ getParser: getParser,
+ setMaxCache: setMaxCache,
+ clearCache: clearCache
+};