Update Bot
This commit is contained in:
4
node_modules/named-placeholders/README.md
generated
vendored
4
node_modules/named-placeholders/README.md
generated
vendored
@@ -1,3 +1,5 @@
|
||||
[](https://flattr.com/submit/auto?user_id=sidorares&url=https://github.com/sidorares/named-placeholders&title=named-placeholders&language=&tags=github&category=software)
|
||||
|
||||
[](https://nodei.co/npm/named-placeholders/)
|
||||
|
||||
[](https://github.com/mysqljs/named-placeholders/actions/workflows/ci.yml)
|
||||
@@ -18,7 +20,7 @@ see [this mysql2 discussion](https://github.com/sidorares/node-mysql2/issues/117
|
||||
var mysql = require('mysql');
|
||||
var toUnnamed = require('named-placeholders')();
|
||||
|
||||
var q = toUnnamed('select 1+:test', { test: 123 });
|
||||
var q = toUnnamed('select 1+:test', { test: 123});
|
||||
mysql.createConnection().query(q[0], q[1]);
|
||||
```
|
||||
|
||||
|
||||
60
node_modules/named-placeholders/index.js
generated
vendored
60
node_modules/named-placeholders/index.js
generated
vendored
@@ -4,9 +4,9 @@
|
||||
// License: https://github.com/mscdex/node-mariasql/blob/master/LICENSE
|
||||
|
||||
const RE_PARAM = /(?:\?)|(?::(\d+|(?:[a-zA-Z][a-zA-Z0-9_]*)))/g,
|
||||
DQUOTE = 34,
|
||||
SQUOTE = 39,
|
||||
BSLASH = 92;
|
||||
DQUOTE = 34,
|
||||
SQUOTE = 39,
|
||||
BSLASH = 92;
|
||||
|
||||
function parse(query) {
|
||||
let ppos = RE_PARAM.exec(query);
|
||||
@@ -24,9 +24,10 @@ function parse(query) {
|
||||
|
||||
if (ppos) {
|
||||
do {
|
||||
for (i = curpos, end = ppos.index; i < end; ++i) {
|
||||
const chr = query.charCodeAt(i);
|
||||
if (chr === BSLASH) escape = !escape;
|
||||
for (i=curpos,end=ppos.index; i<end; ++i) {
|
||||
let chr = query.charCodeAt(i);
|
||||
if (chr === BSLASH)
|
||||
escape = !escape;
|
||||
else {
|
||||
if (escape) {
|
||||
escape = false;
|
||||
@@ -39,7 +40,7 @@ function parse(query) {
|
||||
continue;
|
||||
}
|
||||
inQuote = false;
|
||||
} else if (!inQuote && (chr === DQUOTE || chr === SQUOTE)) {
|
||||
} else if (chr === DQUOTE || chr === SQUOTE) {
|
||||
inQuote = true;
|
||||
qchr = chr;
|
||||
}
|
||||
@@ -52,7 +53,7 @@ function parse(query) {
|
||||
lastTokenEndPos = start;
|
||||
}
|
||||
curpos = end + ppos[0].length;
|
||||
} while ((ppos = RE_PARAM.exec(query)));
|
||||
} while (ppos = RE_PARAM.exec(query));
|
||||
|
||||
if (tokens.length) {
|
||||
if (curpos < query.length) {
|
||||
@@ -62,10 +63,11 @@ function parse(query) {
|
||||
}
|
||||
}
|
||||
return [query];
|
||||
}
|
||||
};
|
||||
|
||||
function createCompiler(config) {
|
||||
if (!config) config = {};
|
||||
if (!config)
|
||||
config = {};
|
||||
if (!config.placeholder) {
|
||||
config.placeholder = '?';
|
||||
}
|
||||
@@ -78,51 +80,49 @@ function createCompiler(config) {
|
||||
cache = config.cache;
|
||||
}
|
||||
if (config.cache !== false && !cache) {
|
||||
cache = require('lru.min').createLRU({ max: ncache });
|
||||
cache = new (require('lru-cache'))({ max: ncache });
|
||||
}
|
||||
|
||||
function toArrayParams(tree, params) {
|
||||
const arr = [];
|
||||
if (tree.length === 1) {
|
||||
if (tree.length == 1) {
|
||||
return [tree[0], []];
|
||||
}
|
||||
|
||||
if (typeof params === 'undefined')
|
||||
throw new Error(
|
||||
'Named query contains placeholders, but parameters object is undefined'
|
||||
);
|
||||
if (typeof params == 'undefined')
|
||||
throw new Error('Named query contains placeholders, but parameters object is undefined');
|
||||
|
||||
const tokens = tree[1];
|
||||
for (let i = 0; i < tokens.length; ++i) {
|
||||
for (let i=0; i < tokens.length; ++i) {
|
||||
arr.push(params[tokens[i]]);
|
||||
}
|
||||
return [tree[0], arr];
|
||||
}
|
||||
|
||||
function noTailingSemicolon(s) {
|
||||
if (s.slice(-1) === ':') {
|
||||
if (s.slice(-1) == ':') {
|
||||
return s.slice(0, -1);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
function join(tree) {
|
||||
if (tree.length === 1) {
|
||||
if (tree.length == 1) {
|
||||
return tree;
|
||||
}
|
||||
|
||||
let unnamed = noTailingSemicolon(tree[0][0]);
|
||||
for (let i = 1; i < tree[0].length; ++i) {
|
||||
if (tree[0][i - 1].slice(-1) === ':') {
|
||||
for (let i=1; i < tree[0].length; ++i) {
|
||||
if (tree[0][i-1].slice(-1) == ':') {
|
||||
unnamed += config.placeholder;
|
||||
}
|
||||
unnamed += config.placeholder;
|
||||
unnamed += noTailingSemicolon(tree[0][i]);
|
||||
}
|
||||
|
||||
const last = tree[0][tree[0].length - 1];
|
||||
if (tree[0].length === tree[1].length) {
|
||||
if (last.slice(-1) === ':') {
|
||||
const last = tree[0][tree[0].length -1];
|
||||
if (tree[0].length == tree[1].length) {
|
||||
if (last.slice(-1) == ':') {
|
||||
unnamed += config.placeholder;
|
||||
}
|
||||
unnamed += config.placeholder;
|
||||
@@ -133,10 +133,10 @@ function createCompiler(config) {
|
||||
function compile(query, paramsObj) {
|
||||
let tree;
|
||||
if (cache && (tree = cache.get(query))) {
|
||||
return toArrayParams(tree, paramsObj);
|
||||
return toArrayParams(tree, paramsObj)
|
||||
}
|
||||
tree = join(parse(query));
|
||||
if (cache) {
|
||||
if(cache) {
|
||||
cache.set(query, tree);
|
||||
}
|
||||
return toArrayParams(tree, paramsObj);
|
||||
@@ -150,7 +150,7 @@ function createCompiler(config) {
|
||||
function toNumbered(q, params) {
|
||||
const tree = parse(q);
|
||||
const paramsArr = [];
|
||||
if (tree.length === 1) {
|
||||
if (tree.length == 1) {
|
||||
return [tree[0], paramsArr];
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ function toNumbered(q, params) {
|
||||
let qs = '';
|
||||
let varIndex;
|
||||
const varNames = [];
|
||||
for (let i = 0; i < tree[0].length; ++i) {
|
||||
for (let i=0; i < tree[0].length; ++i) {
|
||||
varIndex = pIndexes[tree[1][i]];
|
||||
if (!varIndex) {
|
||||
varIndex = ++pLastIndex;
|
||||
@@ -167,12 +167,12 @@ function toNumbered(q, params) {
|
||||
}
|
||||
if (tree[1][i]) {
|
||||
varNames[varIndex - 1] = tree[1][i];
|
||||
qs += `${tree[0][i]}$${varIndex}`;
|
||||
qs += tree[0][i] + '$' + varIndex;
|
||||
} else {
|
||||
qs += tree[0][i];
|
||||
}
|
||||
}
|
||||
return [qs, varNames.map((n) => params[n])];
|
||||
return [qs, varNames.map(n => params[n])];
|
||||
}
|
||||
|
||||
module.exports = createCompiler;
|
||||
|
||||
24
node_modules/named-placeholders/package.json
generated
vendored
24
node_modules/named-placeholders/package.json
generated
vendored
@@ -1,36 +1,32 @@
|
||||
{
|
||||
"name": "named-placeholders",
|
||||
"version": "1.1.6",
|
||||
"version": "1.1.3",
|
||||
"description": "sql named placeholders to unnamed compiler",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "node --test",
|
||||
"lint": "biome lint --error-on-warnings && prettier --check .",
|
||||
"lint:fix": "biome lint --write && prettier --write .github/workflows/*.yml ."
|
||||
"test": "mocha"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mysqljs/named-placeholders"
|
||||
"url": "https://github.com/sidorares/named-placeholders"
|
||||
},
|
||||
"keywords": [
|
||||
"sql",
|
||||
"pdo",
|
||||
"named",
|
||||
"placeholders",
|
||||
"mysql",
|
||||
"postgres"
|
||||
"placeholders"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=8.0.0"
|
||||
"node": ">=12.0.0"
|
||||
},
|
||||
"author": "Andrey Sidorov <sidorares@yandex.com>",
|
||||
"files": [],
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"lru.min": "^1.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "^2.3.8",
|
||||
"prettier": "^3.7.4"
|
||||
"mocha": "^5.2.0",
|
||||
"should": "^13.2.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"lru-cache": "^7.14.1"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user