Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sqb

Package Overview
Dependencies
Maintainers
1
Versions
174
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sqb - npm Package Compare versions

Comparing version 0.9.1 to 0.9.3

2

lib/index.js

@@ -53,2 +53,4 @@ /* SQB

ParamType: Serializer.ParamType,
select: function(column) {

@@ -55,0 +57,0 @@ const q = Object.create(SelectQuery.prototype);

125

lib/serializer.js

@@ -26,2 +26,8 @@ /* SQB

const ParamType = {
COLON: 1,
QUESTION_MARK: 2,
DOLLAR: 3
};
/**

@@ -43,2 +49,3 @@ * Expose `Serializer`.

this.pluginSerializer = plugins.createSerializer(self._config);
self._config.paramType = self._config.paramType || ParamType.COLON;
}

@@ -64,8 +71,8 @@

get namedParams() {
return this._config.namedParams;
get paramType() {
return this._config.paramType;
},
set namedParams(val) {
this._config.namedParams = val;
set paramType(val) {
this._config.paramType = val;
},

@@ -123,3 +130,3 @@

this.config = Object.assign({}, owner._config);
this.outParams = owner.namedParams ? {} : [];
this.outParams = owner.paramType === ParamType.COLON ? {} : [];
this.outParamsCache = {};

@@ -603,3 +610,3 @@ this.prmGen = {generator: 0};

group._items.forEach(function(item) {
assert.ok(['raw', 'conditiongroup', 'condition'].indexOf(item.type)>=0,
assert.ok(['raw', 'conditiongroup', 'condition'].indexOf(item.type) >= 0,
'Invalid object used as Condition');

@@ -640,3 +647,3 @@ logop = item.logicalOperator || logop;

var str;
if (['raw', 'select'].indexOf(item.field.type)>=0) {
if (['raw', 'select'].indexOf(item.field.type) >= 0) {
str = (str = __serialize(self, item.field, inf)) &&

@@ -663,12 +670,3 @@ item.field.type === 'select' ?

if (prm) {
const valIsArray = Array.isArray(prmValue);
if (self.config.namedParams) {
s = ':' + prm + '1 and :' + prm + '2';
outParams[prm + '1'] = valIsArray ? prmValue[0] : prmValue;
outParams[prm + '2'] = valIsArray ? prmValue[1] : null;
} else {
s = '? and ?';
outParams.push(valIsArray ? prmValue[0] : prmValue);
outParams.push(valIsArray ? prmValue[1] : null);
}
s = self.serializeParam(prm, prmValue, true);
} else {

@@ -682,3 +680,4 @@ s = serializeValue(self, item.value[0], inf) + ' and ' +

Array.isArray(item.value) &&
(s = item.value.join()) && ((s.indexOf('%')>=0) || s.indexOf('?')>=0)) {
(s = item.value.join()) &&
((s.indexOf('%') >= 0) || s.indexOf('?') >= 0)) {
s = '(';

@@ -693,13 +692,7 @@ item.value.forEach(function(v, i) {

} else if (prm) {
if (self.config.namedParams) {
s = ':' + prm;
outParams[prm] = prmValue;
} else {
s = '?';
outParams.push(prmValue);
}
s = self.serializeParam(prm, prmValue);
} else {
s = serializeValue(self, item.value, inf);
if (s.startsWith('(')) {
if (['!=', '<>', ' not like'].indexOf(operator)>=0) operator = 'not in';
if (['!=', '<>', ' not like'].indexOf(operator) >= 0) operator = 'not in';
else operator = 'in';

@@ -714,2 +707,43 @@ }

proto2.serializeParam = function(prm, prmValue, multi) {
const valIsArray = Array.isArray(prmValue);
const outParams = this.outParams;
var s;
switch (this.config.paramType) {
case ParamType.COLON:
case undefined:
if (multi) {
s = ':' + prm + '1 and :' + prm + '2';
outParams[prm + '1'] = (valIsArray ? prmValue[0] : prmValue);
outParams[prm + '2'] = (valIsArray ? prmValue[1] : null);
} else {
s = ':' + prm;
outParams[prm] = prmValue || null;
}
break;
case ParamType.DOLLAR:
if (multi) {
s = '$' + (outParams.length + 1) + ' and ' +
'$' + (outParams.length + 2);
outParams.push(valIsArray ? prmValue[0] : prmValue);
outParams.push(valIsArray ? prmValue[1] : null);
} else {
s = '$' + (outParams.length + 1);
outParams.push(prmValue || null);
}
break;
case ParamType.QUESTION_MARK:
if (multi) {
s = '? and ?';
outParams.push(valIsArray ? prmValue[0] : prmValue);
outParams.push(valIsArray ? prmValue[1] : null);
} else {
s = '?';
outParams.push(prmValue || null);
}
break;
}
return s;
};
//noinspection JSUnusedLocalSymbols,JSUnusedGlobalSymbols

@@ -743,17 +777,15 @@ /**

}
if (self.config.namedParams) {
self.outParams[prm] = x;
return ':' + prm;
} else {
self.outParams.push(x);
return '?';
}
return self.serializeParam(prm, x);
}
if (val.isRaw)
return serializeRaw(self, val, inf);
var s;
if (val.type === 'select') {
const s = serializeSelect(self, val);
s = serializeSelect(self, val);
return s ? '(' + s + ')' : 'null';
}
if (val.type === 'case') {
s = serializeCase(self, val);
return s ? '(' + s + ')' : 'null';
}
if (typeof val === 'string')

@@ -881,9 +913,3 @@ return serializeStringValue(self, val, inf);

const x = self.inputValues && self.inputValues[key];
if (self.config.namedParams) {
s = ':' + key;
self.outParams[key] = x;
} else {
s = '?';
self.outParams.push(x);
}
s = self.serializeParam(key, x);
} else

@@ -911,3 +937,3 @@ s = serializeValue(self, value, inf);

assert.ok(['conditiongroup', 'condition', 'raw'].indexOf(
item.condition.type)>=0,
item.condition.type) >= 0,
'Invalid object used in "case" expression');

@@ -928,3 +954,3 @@ const s = __serialize(self, item.condition, iinf);

out += '\bend' + (obj._alias ? ' ' + obj._alias : '');
return flattenText(out, {noWrap: out.length < 60});
return out;
}

@@ -972,2 +998,6 @@ };

function serializeCase(instance, columns, inf) {
return __serialize('serializeCase', instance, columns, inf);
}
function serializeColumns(instance, columns, inf) {

@@ -1037,2 +1067,6 @@ return __serialize('serializeColumns', instance, columns, inf);

function getConfig(instance, bindings, inf) {
}
function __serialize(fnName, instance, obj, inf) {

@@ -1045,3 +1079,3 @@

if (obj !== instance.query &&
['select', 'insert', 'update', 'delete'].indexOf(obj.type)>=0) {
['select', 'insert', 'update', 'delete'].indexOf(obj.type) >= 0) {
const sub = new SerializerInstance(instance);

@@ -1075,2 +1109,3 @@ return sub.generate(obj, instance.inputValues);

Serializer.ParamType = ParamType;
module.exports = Serializer;

@@ -34,3 +34,3 @@ /* SQB

throw new ArgumentError('Invalid value (%s) for `field` argument', field);
} else if (!(field && (field.type === 'select' || field.type === 'raw')))
} else if (!(field && (['select', 'raw'].indexOf(field.type) >= 0)))
throw new ArgumentError('Invalid type (%s) for `field` argument', field.type);

@@ -37,0 +37,0 @@ this.type = 'condition';

@@ -72,4 +72,4 @@ /* SQB

self._items.push(c);
} else if (typeof arg[0] === 'string' || arg[0].type === 'select' ||
arg[0].type === 'raw') {
} else if (typeof arg[0] === 'string' || (
['select', 'raw'].indexOf(arg[0].type) >= 0)) {
c = Object.create(Condition.prototype);

@@ -76,0 +76,0 @@ Condition.apply(c, arg);

{
"name": "sqb",
"description": "Plugin-driven, multi-dialect SQL query builder and Database connection framework for JavaScript",
"version": "0.9.1",
"version": "0.9.3",
"author": "Panates Ltd.",

@@ -6,0 +6,0 @@ "contributors": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc