New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

squel

Package Overview
Dependencies
Maintainers
1
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

squel - npm Package Compare versions

Comparing version 1.2.0 to 1.2.1

2

bower.json
{
"name": "squel",
"version": "1.2.0",
"version": "1.2.1",
"main": "squel.js",

@@ -5,0 +5,0 @@ "ignore": [

# Changelog for [squel](https://github.com/hiddentao/squel)
## 7 Oct 2013 (1.2.1)
* Added ON DUPLICATE KEY UPDATE clause for MySQL flavour (#36)
* Added single quote replacement option for Postgres flavour (#35)
## 2 Oct 2013 (1.2)

@@ -5,0 +10,0 @@ * Switched from Make to Grunt

@@ -24,3 +24,3 @@ 'use strict';

files: [{
src: ['src/squel.coffee', 'src/postgres.coffee'],
src: ['src/squel.coffee', 'src/postgres.coffee', 'src/mysql.coffee'],
dest: './squel.js'

@@ -27,0 +27,0 @@ }]

{
"name": "squel",
"description": "SQL query string builder",
"version": "1.2.0",
"version": "1.2.1",
"author": "Ramesh Nair <ram@hiddentao.com> (http://www.hiddentao.com/)",

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

/*
Copyright (c) 2012-2013 Ramesh Nair (hiddentao.com)
Copyright (c) Ramesh Nair (hiddentao.com)

@@ -238,2 +238,6 @@ Permission is hereby granted, free of charge, to any person

BaseBuilder.prototype._escapeValue = function(str) {
return str;
};
BaseBuilder.prototype._formatValue = function(value) {

@@ -251,2 +255,3 @@ var customHandler;

if (false === this.options.usingValuePlaceholders) {
value = this._escapeValue(value);
value = "'" + value + "'";

@@ -253,0 +258,0 @@ }

@@ -1,1 +0,1 @@

/*! squel | https://github.com/hiddentao/squel | BSD license */(function(){var a,b,c,d,e,f,g,h,i=[].slice,j={}.hasOwnProperty,k=function(a,b){function c(){this.constructor=a}for(var d in b)j.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};a={},e=function(){var a,b,c,d,e,f,g;if(a=arguments[0],c=2<=arguments.length?i.call(arguments,1):[])for(f=0,g=c.length;g>f;f++)if(d=c[f])for(b in d)j.call(d,b)&&(e=d[b],a[b]=e);return a},a.DefaultQueryBuilderOptions={autoQuoteTableNames:!1,autoQuoteFieldNames:!1,autoQuoteAliasNames:!0,nameQuoteCharacter:"`",tableAliasQuoteCharacter:"`",fieldAliasQuoteCharacter:'"',usingValuePlaceholders:!1,valueHandlers:[]},a.globalValueHandlers=[],c=function(a,b,c){var d,e,f;if("function"!=typeof b)throw new Error("type must be a class constructor");if("function"!=typeof c)throw new Error("handler must be a function");for(e=0,f=a.length;f>e;e++)if(d=a[e],d.type===b)return d.handler=c,void 0;return a.push({type:b,handler:c})},b=function(){var a,b,c,d,e,f,g,h;for(d=arguments[0],a=2<=arguments.length?i.call(arguments,1):[],e=0,g=a.length;g>e;e++)for(b=a[e],f=0,h=b.length;h>f;f++)if(c=b[f],d instanceof c.type)return c.handler;return void 0},a.registerValueHandler=function(b,d){return c(a.globalValueHandlers,b,d)},a.Cloneable=function(){function a(){}return a.prototype.clone=function(){var a;return a=new this.constructor,e(a,JSON.parse(JSON.stringify(this)))},a}(),a.BaseBuilder=function(d){function f(b){var c;c=JSON.parse(JSON.stringify(a.DefaultQueryBuilderOptions)),this.options=e({},c,b)}return k(f,d),f.prototype.registerValueHandler=function(a,b){return c(this.options.valueHandlers,a,b),this},f.prototype._getObjectClassName=function(a){var b;return a&&a.constructor&&a.constructor.toString&&(b=a.constructor.toString().match(/function\s*(\w+)/),b&&2===b.length)?b[1]:void 0},f.prototype._sanitizeCondition=function(b){if(b instanceof a.Expression&&(b=b.toString()),"string"!=typeof b)throw new Error("condition must be a string or Expression instance");return b},f.prototype._sanitizeName=function(a,b){if("string"!=typeof a)throw new Error(""+b+" must be a string");return a},f.prototype._sanitizeField=function(a){var b;return b=this._sanitizeName(a,"field name"),this.options.autoQuoteFieldNames?""+this.options.nameQuoteCharacter+b+this.options.nameQuoteCharacter:b},f.prototype._sanitizeTable=function(b,c){var d;if(null==c&&(c=!1),c){if("string"!=typeof b){if(b instanceof a.QueryBuilder&&b.isNestable())return b;throw new Error("table name must be a string or a nestable query instance")}d=b}else d=this._sanitizeName(b,"table name");return this.options.autoQuoteTableNames?""+this.options.nameQuoteCharacter+d+this.options.nameQuoteCharacter:d},f.prototype._sanitizeTableAlias=function(a){var b;return b=this._sanitizeName(a,"table alias"),this.options.autoQuoteAliasNames?""+this.options.tableAliasQuoteCharacter+b+this.options.tableAliasQuoteCharacter:b},f.prototype._sanitizeFieldAlias=function(a){var b;return b=this._sanitizeName(a,"field alias"),this.options.autoQuoteAliasNames?""+this.options.fieldAliasQuoteCharacter+b+this.options.fieldAliasQuoteCharacter:b},f.prototype._sanitizeLimitOffset=function(a){if(a=parseInt(a),0>a||isNaN(a))throw new Error("limit/offset must be >= 0");return a},f.prototype._sanitizeValue=function(c){var d,e;if(d=typeof c,null===c);else if("string"===d||"number"===d||"boolean"===d);else if(e=void 0!==b(c,this.options.valueHandlers,a.globalValueHandlers),!e)throw new Error("field value must be a string, number, boolean, null or one of the registered custom value types");return c},f.prototype._formatValue=function(c){var d;return d=b(c,this.options.valueHandlers,a.globalValueHandlers),d&&(c=d(c)),null===c?c="NULL":"boolean"==typeof c?c=c?"TRUE":"FALSE":"number"!=typeof c&&!1===this.options.usingValuePlaceholders&&(c="'"+c+"'"),c},f}(a.Cloneable),a.Expression=function(a){function b(){var a=this;this.tree={parent:null,nodes:[]},this.current=this.tree,this._begin=function(b){var c;return c={type:b,parent:a.current,nodes:[]},a.current.nodes.push(c),a.current=a.current.nodes[a.current.nodes.length-1],a}}var c;return k(b,a),b.prototype.tree=null,b.prototype.current=null,b.prototype.and_begin=function(){return this._begin("AND")},b.prototype.or_begin=function(){return this._begin("OR")},b.prototype.end=function(){if(!this.current.parent)throw new Error("begin() needs to be called");return this.current=this.current.parent,this},b.prototype.and=function(a){if(!a||"string"!=typeof a)throw new Error("expr must be a string");return this.current.nodes.push({type:"AND",expr:a}),this},b.prototype.or=function(a){if(!a||"string"!=typeof a)throw new Error("expr must be a string");return this.current.nodes.push({type:"OR",expr:a}),this},b.prototype.toString=function(){if(null!==this.current.parent)throw new Error("end() needs to be called");return c(this.tree)},c=function(a){var b,d,e,f,g,h;for(e="",h=a.nodes,f=0,g=h.length;g>f;f++)b=h[f],null!=b.expr?d=b.expr:(d=c(b),""!==d&&(d="("+d+")")),""!==d&&(""!==e&&(e+=" "+b.type+" "),e+=d);return e},b.prototype.clone=function(){var a,b;return a=new this.constructor,(b=function(c){var d,e,f,g,h;for(g=c.nodes,h=[],e=0,f=g.length;f>e;e++)d=g[e],null!=d.expr?h.push(a.current.nodes.push(JSON.parse(JSON.stringify(d)))):(a._begin(d.type),b(d),!this.current===d?h.push(a.end()):h.push(void 0));return h})(this.tree),a},b}(a.Cloneable),a.Block=function(b){function c(){return f=c.__super__.constructor.apply(this,arguments)}return k(c,b),c.prototype.exposedMethods=function(){var b,c,d;c={};for(b in this)d=this[b],"function"!=typeof d||"_"===b.charAt(0)||a.Block.prototype[b]||(c[b]=d);return c},c.prototype.buildStr=function(){return""},c}(a.BaseBuilder),a.StringBlock=function(a){function b(a,c){b.__super__.constructor.call(this,a),this.str=c}return k(b,a),b.prototype.buildStr=function(){return this.str},b}(a.Block),a.AbstractTableBlock=function(a){function b(a){b.__super__.constructor.call(this,a),this.tables=[]}return k(b,a),b.prototype._table=function(a,b){return null==b&&(b=null),b&&(b=this._sanitizeTableAlias(b)),a=this._sanitizeTable(a,this.options.allowNested||!1),this.options.singleTable&&(this.tables=[]),this.tables.push({table:a,alias:b})},b.prototype.buildStr=function(){var a,b,c,d,e;if(0>=this.tables.length)throw new Error("_table() needs to be called");for(b="",e=this.tables,c=0,d=e.length;d>c;c++)a=e[c],""!==b&&(b+=", "),b+="string"==typeof a.table?a.table:"("+a.table+")",a.alias&&(b+=" "+a.alias);return b},b}(a.Block),a.UpdateTableBlock=function(a){function b(){return g=b.__super__.constructor.apply(this,arguments)}return k(b,a),b.prototype.table=function(a,b){return null==b&&(b=null),this._table(a,b)},b}(a.AbstractTableBlock),a.FromTableBlock=function(a){function b(){return h=b.__super__.constructor.apply(this,arguments)}return k(b,a),b.prototype.from=function(a,b){return null==b&&(b=null),this._table(a,b)},b.prototype.buildStr=function(a){var c;if(0>=this.tables.length)throw new Error("from() needs to be called");return c=b.__super__.buildStr.call(this,a),"FROM "+c},b}(a.AbstractTableBlock),a.IntoTableBlock=function(a){function b(a){b.__super__.constructor.call(this,a),this.table=null}return k(b,a),b.prototype.into=function(a){return this.table=this._sanitizeTable(a,!1)},b.prototype.buildStr=function(){if(!this.table)throw new Error("into() needs to be called");return"INTO "+this.table},b}(a.Block),a.GetFieldBlock=function(a){function b(a){b.__super__.constructor.call(this,a),this._fields=[]}return k(b,a),b.prototype.fields=function(a){var b,c,d;d=[];for(c in a)b=a[c],d.push(this.field(c,b));return d},b.prototype.field=function(a,b){return null==b&&(b=null),a=this._sanitizeField(a),b&&(b=this._sanitizeFieldAlias(b)),this._fields.push({name:a,alias:b})},b.prototype.buildStr=function(){var a,b,c,d,e;for(b="",e=this._fields,c=0,d=e.length;d>c;c++)a=e[c],""!==b&&(b+=", "),b+=a.name,a.alias&&(b+=" AS "+a.alias);return""===b?"*":b},b}(a.Block),a.SetFieldBlock=function(a){function b(a){b.__super__.constructor.call(this,a),this.fields={}}return k(b,a),b.prototype.set=function(a,b){return a=this._sanitizeField(a),b=this._sanitizeValue(b),this.fields[a]=b,this},b.prototype.buildStr=function(){var a,b,c,d,e;if(b=function(){var b,c;b=this.fields,c=[];for(a in b)j.call(b,a)&&c.push(a);return c}.call(this),0>=b.length)throw new Error("set() needs to be called");for(c="",d=0,e=b.length;e>d;d++)a=b[d],""!==c&&(c+=", "),c+=""+a+" = "+this._formatValue(this.fields[a]);return"SET "+c},b}(a.Block),a.InsertFieldValueBlock=function(a){function b(a){b.__super__.constructor.call(this,a),this.fields={}}return k(b,a),b.prototype.buildStr=function(){var a,b,c,d,e,f,g;if(b=function(){var a,b;a=this.fields,b=[];for(d in a)j.call(a,d)&&b.push(d);return b}.call(this),0>=b.length)throw new Error("set() needs to be called");for(c="",e="",f=0,g=b.length;g>f;f++)a=b[f],""!==c&&(c+=", "),c+=a,""!==e&&(e+=", "),e+=this._formatValue(this.fields[a]);return"("+c+") VALUES ("+e+")"},b}(a.SetFieldBlock),a.DistinctBlock=function(a){function b(a){b.__super__.constructor.call(this,a),this.useDistinct=!1}return k(b,a),b.prototype.distinct=function(){return this.useDistinct=!0},b.prototype.buildStr=function(){return this.useDistinct?"DISTINCT":""},b}(a.Block),a.GroupByBlock=function(a){function b(a){b.__super__.constructor.call(this,a),this.groups=[]}return k(b,a),b.prototype.group=function(a){return a=this._sanitizeField(a),this.groups.push(a)},b.prototype.buildStr=function(){var a,b,c,d,e;if(b="",0<this.groups.length){for(e=this.groups,c=0,d=e.length;d>c;c++)a=e[c],""!==b&&(b+=", "),b+=a;b="GROUP BY "+b}return b},b}(a.Block),a.OffsetBlock=function(a){function b(a){b.__super__.constructor.call(this,a),this.offsets=null}return k(b,a),b.prototype.offset=function(a){return a=this._sanitizeLimitOffset(a),this.offsets=a},b.prototype.buildStr=function(){return this.offsets?"OFFSET "+this.offsets:""},b}(a.Block),a.WhereBlock=function(a){function b(a){b.__super__.constructor.call(this,a),this.wheres=[]}return k(b,a),b.prototype.where=function(){var a,b,c,d,e,f,g,h,j;for(a=arguments[0],e=2<=arguments.length?i.call(arguments,1):[],a=this._sanitizeCondition(a),f=0,h=e.length;h>f;f++){if(d=e[f],Array.isArray(d)){for(b=[],g=0,j=d.length;j>g;g++)c=d[g],b.push(this._formatValue(this._sanitizeValue(c)));d="("+b.join(", ")+")"}else d=this._formatValue(this._sanitizeValue(d));a=a.replace("?",d)}return""!==a?this.wheres.push(a):void 0},b.prototype.buildStr=function(){return 0<this.wheres.length?"WHERE ("+this.wheres.join(") AND (")+")":""},b}(a.Block),a.OrderByBlock=function(a){function b(a){b.__super__.constructor.call(this,a),this.orders=[]}return k(b,a),b.prototype.order=function(a,b){return null==b&&(b=!0),a=this._sanitizeField(a),this.orders.push({field:a,dir:b?!0:!1})},b.prototype.buildStr=function(){var a,b,c,d,e;if(0<this.orders.length){for(b="",e=this.orders,c=0,d=e.length;d>c;c++)a=e[c],""!==b&&(b+=", "),b+=""+a.field+" "+(a.dir?"ASC":"DESC");return"ORDER BY "+b}return""},b}(a.Block),a.LimitBlock=function(a){function b(a){b.__super__.constructor.call(this,a),this.limits=null}return k(b,a),b.prototype.limit=function(a){return a=this._sanitizeLimitOffset(a),this.limits=a},b.prototype.buildStr=function(){return this.limits?"LIMIT "+this.limits:""},b}(a.Block),a.JoinBlock=function(a){function b(a){b.__super__.constructor.call(this,a),this.joins=[]}return k(b,a),b.prototype.join=function(a,b,c,d){return null==b&&(b=null),null==c&&(c=null),null==d&&(d="INNER"),a=this._sanitizeTable(a,!0),b&&(b=this._sanitizeTableAlias(b)),c&&(c=this._sanitizeCondition(c)),this.joins.push({type:d,table:a,alias:b,condition:c}),this},b.prototype.left_join=function(a,b,c){return null==b&&(b=null),null==c&&(c=null),this.join(a,b,c,"LEFT")},b.prototype.right_join=function(a,b,c){return null==b&&(b=null),null==c&&(c=null),this.join(a,b,c,"RIGHT")},b.prototype.outer_join=function(a,b,c){return null==b&&(b=null),null==c&&(c=null),this.join(a,b,c,"OUTER")},b.prototype.buildStr=function(){var a,b,c,d,e;for(b="",e=this.joins||[],c=0,d=e.length;d>c;c++)a=e[c],""!==b&&(b+=" "),b+=""+a.type+" JOIN ",b+="string"==typeof a.table?a.table:"("+a.table+")",a.alias&&(b+=" "+a.alias),a.condition&&(b+=" ON ("+a.condition+")");return b},b}(a.Block),a.QueryBuilder=function(a){function b(a,c){var d,e,f,g,h,i,j,k,l=this;for(b.__super__.constructor.call(this,a),this.blocks=c||[],j=this.blocks,h=0,i=j.length;i>h;h++){d=j[h],k=d.exposedMethods(),g=function(a,b,c){return l[b]=function(){return c.apply(a,arguments),l}};for(f in k){if(e=k[f],null!=this[f])throw new Error(""+this._getObjectClassName(this)+" already has a builder method called: "+f);g(d,f,e)}}}return k(b,a),b.prototype.registerValueHandler=function(a,c){var d,e,f,g;for(g=this.blocks,e=0,f=g.length;f>e;e++)d=g[e],d.registerValueHandler(a,c);return b.__super__.registerValueHandler.call(this,a,c),this},b.prototype.updateOptions=function(a){var b,c,d,f,g;for(this.options=e({},this.options,a),f=this.blocks,g=[],c=0,d=f.length;d>c;c++)b=f[c],g.push(b.options=e({},b.options,a));return g},b.prototype.toString=function(){var a;return function(){var b,c,d,e;for(d=this.blocks,e=[],b=0,c=d.length;c>b;b++)a=d[b],e.push(a.buildStr(this));return e}.call(this).filter(function(a){return 0<a.length}).join(" ")},b.prototype.clone=function(){var a;return new this.constructor(this.options,function(){var b,c,d,e;for(d=this.blocks,e=[],b=0,c=d.length;c>b;b++)a=d[b],e.push(a.clone());return e}.call(this))},b.prototype.isNestable=function(){return!1},b}(a.BaseBuilder),a.Select=function(b){function c(b,d){null==d&&(d=null),d||(d=[new a.StringBlock(b,"SELECT"),new a.DistinctBlock(b),new a.GetFieldBlock(b),new a.FromTableBlock(e({},b,{allowNested:!0})),new a.JoinBlock(e({},b,{allowNested:!0})),new a.WhereBlock(b),new a.GroupByBlock(b),new a.OrderByBlock(b),new a.LimitBlock(b),new a.OffsetBlock(b)]),c.__super__.constructor.call(this,b,d)}return k(c,b),c.prototype.isNestable=function(){return!0},c}(a.QueryBuilder),a.Update=function(b){function c(b,d){null==d&&(d=null),d||(d=[new a.StringBlock(b,"UPDATE"),new a.UpdateTableBlock(b),new a.SetFieldBlock(b),new a.WhereBlock(b),new a.OrderByBlock(b),new a.LimitBlock(b)]),c.__super__.constructor.call(this,b,d)}return k(c,b),c}(a.QueryBuilder),a.Delete=function(b){function c(b,d){null==d&&(d=null),d||(d=[new a.StringBlock(b,"DELETE"),new a.FromTableBlock(e({},b,{singleTable:!0})),new a.JoinBlock(b),new a.WhereBlock(b),new a.OrderByBlock(b),new a.LimitBlock(b)]),c.__super__.constructor.call(this,b,d)}return k(c,b),c}(a.QueryBuilder),a.Insert=function(b){function c(b,d){null==d&&(d=null),d||(d=[new a.StringBlock(b,"INSERT"),new a.IntoTableBlock(b),new a.InsertFieldValueBlock(b)]),c.__super__.constructor.call(this,b,d)}return k(c,b),c}(a.QueryBuilder),d={expr:function(){return new a.Expression},select:function(b,c){return new a.Select(b,c)},update:function(b,c){return new a.Update(b,c)},insert:function(b,c){return new a.Insert(b,c)},"delete":function(b,c){return new a.Delete(b,c)},registerValueHandler:a.registerValueHandler},d.remove=d["delete"],d.cls=a,("undefined"!=typeof define&&null!==define?define.amd:void 0)?define(function(){return d}):("undefined"!=typeof module&&null!==module?module.exports:void 0)?module.exports=d:"undefined"!=typeof window&&null!==window&&(window.squel=d),d.flavours={},d.useFlavour=function(a){if(!(d.flavours[a]instanceof Function))throw new Error("Flavour not available: "+a);return d.flavours[a].call(null,d),d}}).call(this);
/*! squel | https://github.com/hiddentao/squel | BSD license */(function(){var a,b,c,d,e,f,g,h,i=[].slice,j={}.hasOwnProperty,k=function(a,b){function c(){this.constructor=a}for(var d in b)j.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};a={},e=function(){var a,b,c,d,e,f,g;if(a=arguments[0],c=2<=arguments.length?i.call(arguments,1):[])for(f=0,g=c.length;g>f;f++)if(d=c[f])for(b in d)j.call(d,b)&&(e=d[b],a[b]=e);return a},a.DefaultQueryBuilderOptions={autoQuoteTableNames:!1,autoQuoteFieldNames:!1,autoQuoteAliasNames:!0,nameQuoteCharacter:"`",tableAliasQuoteCharacter:"`",fieldAliasQuoteCharacter:'"',usingValuePlaceholders:!1,valueHandlers:[]},a.globalValueHandlers=[],c=function(a,b,c){var d,e,f;if("function"!=typeof b)throw new Error("type must be a class constructor");if("function"!=typeof c)throw new Error("handler must be a function");for(e=0,f=a.length;f>e;e++)if(d=a[e],d.type===b)return d.handler=c,void 0;return a.push({type:b,handler:c})},b=function(){var a,b,c,d,e,f,g,h;for(d=arguments[0],a=2<=arguments.length?i.call(arguments,1):[],e=0,g=a.length;g>e;e++)for(b=a[e],f=0,h=b.length;h>f;f++)if(c=b[f],d instanceof c.type)return c.handler;return void 0},a.registerValueHandler=function(b,d){return c(a.globalValueHandlers,b,d)},a.Cloneable=function(){function a(){}return a.prototype.clone=function(){var a;return a=new this.constructor,e(a,JSON.parse(JSON.stringify(this)))},a}(),a.BaseBuilder=function(d){function f(b){var c;c=JSON.parse(JSON.stringify(a.DefaultQueryBuilderOptions)),this.options=e({},c,b)}return k(f,d),f.prototype.registerValueHandler=function(a,b){return c(this.options.valueHandlers,a,b),this},f.prototype._getObjectClassName=function(a){var b;return a&&a.constructor&&a.constructor.toString&&(b=a.constructor.toString().match(/function\s*(\w+)/),b&&2===b.length)?b[1]:void 0},f.prototype._sanitizeCondition=function(b){if(b instanceof a.Expression&&(b=b.toString()),"string"!=typeof b)throw new Error("condition must be a string or Expression instance");return b},f.prototype._sanitizeName=function(a,b){if("string"!=typeof a)throw new Error(""+b+" must be a string");return a},f.prototype._sanitizeField=function(a){var b;return b=this._sanitizeName(a,"field name"),this.options.autoQuoteFieldNames?""+this.options.nameQuoteCharacter+b+this.options.nameQuoteCharacter:b},f.prototype._sanitizeTable=function(b,c){var d;if(null==c&&(c=!1),c){if("string"!=typeof b){if(b instanceof a.QueryBuilder&&b.isNestable())return b;throw new Error("table name must be a string or a nestable query instance")}d=b}else d=this._sanitizeName(b,"table name");return this.options.autoQuoteTableNames?""+this.options.nameQuoteCharacter+d+this.options.nameQuoteCharacter:d},f.prototype._sanitizeTableAlias=function(a){var b;return b=this._sanitizeName(a,"table alias"),this.options.autoQuoteAliasNames?""+this.options.tableAliasQuoteCharacter+b+this.options.tableAliasQuoteCharacter:b},f.prototype._sanitizeFieldAlias=function(a){var b;return b=this._sanitizeName(a,"field alias"),this.options.autoQuoteAliasNames?""+this.options.fieldAliasQuoteCharacter+b+this.options.fieldAliasQuoteCharacter:b},f.prototype._sanitizeLimitOffset=function(a){if(a=parseInt(a),0>a||isNaN(a))throw new Error("limit/offset must be >= 0");return a},f.prototype._sanitizeValue=function(c){var d,e;if(d=typeof c,null===c);else if("string"===d||"number"===d||"boolean"===d);else if(e=void 0!==b(c,this.options.valueHandlers,a.globalValueHandlers),!e)throw new Error("field value must be a string, number, boolean, null or one of the registered custom value types");return c},f.prototype._escapeValue=function(a){return a},f.prototype._formatValue=function(c){var d;return d=b(c,this.options.valueHandlers,a.globalValueHandlers),d&&(c=d(c)),null===c?c="NULL":"boolean"==typeof c?c=c?"TRUE":"FALSE":"number"!=typeof c&&!1===this.options.usingValuePlaceholders&&(c=this._escapeValue(c),c="'"+c+"'"),c},f}(a.Cloneable),a.Expression=function(a){function b(){var a=this;this.tree={parent:null,nodes:[]},this.current=this.tree,this._begin=function(b){var c;return c={type:b,parent:a.current,nodes:[]},a.current.nodes.push(c),a.current=a.current.nodes[a.current.nodes.length-1],a}}var c;return k(b,a),b.prototype.tree=null,b.prototype.current=null,b.prototype.and_begin=function(){return this._begin("AND")},b.prototype.or_begin=function(){return this._begin("OR")},b.prototype.end=function(){if(!this.current.parent)throw new Error("begin() needs to be called");return this.current=this.current.parent,this},b.prototype.and=function(a){if(!a||"string"!=typeof a)throw new Error("expr must be a string");return this.current.nodes.push({type:"AND",expr:a}),this},b.prototype.or=function(a){if(!a||"string"!=typeof a)throw new Error("expr must be a string");return this.current.nodes.push({type:"OR",expr:a}),this},b.prototype.toString=function(){if(null!==this.current.parent)throw new Error("end() needs to be called");return c(this.tree)},c=function(a){var b,d,e,f,g,h;for(e="",h=a.nodes,f=0,g=h.length;g>f;f++)b=h[f],null!=b.expr?d=b.expr:(d=c(b),""!==d&&(d="("+d+")")),""!==d&&(""!==e&&(e+=" "+b.type+" "),e+=d);return e},b.prototype.clone=function(){var a,b;return a=new this.constructor,(b=function(c){var d,e,f,g,h;for(g=c.nodes,h=[],e=0,f=g.length;f>e;e++)d=g[e],null!=d.expr?h.push(a.current.nodes.push(JSON.parse(JSON.stringify(d)))):(a._begin(d.type),b(d),!this.current===d?h.push(a.end()):h.push(void 0));return h})(this.tree),a},b}(a.Cloneable),a.Block=function(b){function c(){return f=c.__super__.constructor.apply(this,arguments)}return k(c,b),c.prototype.exposedMethods=function(){var b,c,d;c={};for(b in this)d=this[b],"function"!=typeof d||"_"===b.charAt(0)||a.Block.prototype[b]||(c[b]=d);return c},c.prototype.buildStr=function(){return""},c}(a.BaseBuilder),a.StringBlock=function(a){function b(a,c){b.__super__.constructor.call(this,a),this.str=c}return k(b,a),b.prototype.buildStr=function(){return this.str},b}(a.Block),a.AbstractTableBlock=function(a){function b(a){b.__super__.constructor.call(this,a),this.tables=[]}return k(b,a),b.prototype._table=function(a,b){return null==b&&(b=null),b&&(b=this._sanitizeTableAlias(b)),a=this._sanitizeTable(a,this.options.allowNested||!1),this.options.singleTable&&(this.tables=[]),this.tables.push({table:a,alias:b})},b.prototype.buildStr=function(){var a,b,c,d,e;if(0>=this.tables.length)throw new Error("_table() needs to be called");for(b="",e=this.tables,c=0,d=e.length;d>c;c++)a=e[c],""!==b&&(b+=", "),b+="string"==typeof a.table?a.table:"("+a.table+")",a.alias&&(b+=" "+a.alias);return b},b}(a.Block),a.UpdateTableBlock=function(a){function b(){return g=b.__super__.constructor.apply(this,arguments)}return k(b,a),b.prototype.table=function(a,b){return null==b&&(b=null),this._table(a,b)},b}(a.AbstractTableBlock),a.FromTableBlock=function(a){function b(){return h=b.__super__.constructor.apply(this,arguments)}return k(b,a),b.prototype.from=function(a,b){return null==b&&(b=null),this._table(a,b)},b.prototype.buildStr=function(a){var c;if(0>=this.tables.length)throw new Error("from() needs to be called");return c=b.__super__.buildStr.call(this,a),"FROM "+c},b}(a.AbstractTableBlock),a.IntoTableBlock=function(a){function b(a){b.__super__.constructor.call(this,a),this.table=null}return k(b,a),b.prototype.into=function(a){return this.table=this._sanitizeTable(a,!1)},b.prototype.buildStr=function(){if(!this.table)throw new Error("into() needs to be called");return"INTO "+this.table},b}(a.Block),a.GetFieldBlock=function(a){function b(a){b.__super__.constructor.call(this,a),this._fields=[]}return k(b,a),b.prototype.fields=function(a){var b,c,d;d=[];for(c in a)b=a[c],d.push(this.field(c,b));return d},b.prototype.field=function(a,b){return null==b&&(b=null),a=this._sanitizeField(a),b&&(b=this._sanitizeFieldAlias(b)),this._fields.push({name:a,alias:b})},b.prototype.buildStr=function(){var a,b,c,d,e;for(b="",e=this._fields,c=0,d=e.length;d>c;c++)a=e[c],""!==b&&(b+=", "),b+=a.name,a.alias&&(b+=" AS "+a.alias);return""===b?"*":b},b}(a.Block),a.SetFieldBlock=function(a){function b(a){b.__super__.constructor.call(this,a),this.fields={}}return k(b,a),b.prototype.set=function(a,b){return a=this._sanitizeField(a),b=this._sanitizeValue(b),this.fields[a]=b,this},b.prototype.buildStr=function(){var a,b,c,d,e;if(b=function(){var b,c;b=this.fields,c=[];for(a in b)j.call(b,a)&&c.push(a);return c}.call(this),0>=b.length)throw new Error("set() needs to be called");for(c="",d=0,e=b.length;e>d;d++)a=b[d],""!==c&&(c+=", "),c+=""+a+" = "+this._formatValue(this.fields[a]);return"SET "+c},b}(a.Block),a.InsertFieldValueBlock=function(a){function b(a){b.__super__.constructor.call(this,a),this.fields={}}return k(b,a),b.prototype.buildStr=function(){var a,b,c,d,e,f,g;if(b=function(){var a,b;a=this.fields,b=[];for(d in a)j.call(a,d)&&b.push(d);return b}.call(this),0>=b.length)throw new Error("set() needs to be called");for(c="",e="",f=0,g=b.length;g>f;f++)a=b[f],""!==c&&(c+=", "),c+=a,""!==e&&(e+=", "),e+=this._formatValue(this.fields[a]);return"("+c+") VALUES ("+e+")"},b}(a.SetFieldBlock),a.DistinctBlock=function(a){function b(a){b.__super__.constructor.call(this,a),this.useDistinct=!1}return k(b,a),b.prototype.distinct=function(){return this.useDistinct=!0},b.prototype.buildStr=function(){return this.useDistinct?"DISTINCT":""},b}(a.Block),a.GroupByBlock=function(a){function b(a){b.__super__.constructor.call(this,a),this.groups=[]}return k(b,a),b.prototype.group=function(a){return a=this._sanitizeField(a),this.groups.push(a)},b.prototype.buildStr=function(){var a,b,c,d,e;if(b="",0<this.groups.length){for(e=this.groups,c=0,d=e.length;d>c;c++)a=e[c],""!==b&&(b+=", "),b+=a;b="GROUP BY "+b}return b},b}(a.Block),a.OffsetBlock=function(a){function b(a){b.__super__.constructor.call(this,a),this.offsets=null}return k(b,a),b.prototype.offset=function(a){return a=this._sanitizeLimitOffset(a),this.offsets=a},b.prototype.buildStr=function(){return this.offsets?"OFFSET "+this.offsets:""},b}(a.Block),a.WhereBlock=function(a){function b(a){b.__super__.constructor.call(this,a),this.wheres=[]}return k(b,a),b.prototype.where=function(){var a,b,c,d,e,f,g,h,j;for(a=arguments[0],e=2<=arguments.length?i.call(arguments,1):[],a=this._sanitizeCondition(a),f=0,h=e.length;h>f;f++){if(d=e[f],Array.isArray(d)){for(b=[],g=0,j=d.length;j>g;g++)c=d[g],b.push(this._formatValue(this._sanitizeValue(c)));d="("+b.join(", ")+")"}else d=this._formatValue(this._sanitizeValue(d));a=a.replace("?",d)}return""!==a?this.wheres.push(a):void 0},b.prototype.buildStr=function(){return 0<this.wheres.length?"WHERE ("+this.wheres.join(") AND (")+")":""},b}(a.Block),a.OrderByBlock=function(a){function b(a){b.__super__.constructor.call(this,a),this.orders=[]}return k(b,a),b.prototype.order=function(a,b){return null==b&&(b=!0),a=this._sanitizeField(a),this.orders.push({field:a,dir:b?!0:!1})},b.prototype.buildStr=function(){var a,b,c,d,e;if(0<this.orders.length){for(b="",e=this.orders,c=0,d=e.length;d>c;c++)a=e[c],""!==b&&(b+=", "),b+=""+a.field+" "+(a.dir?"ASC":"DESC");return"ORDER BY "+b}return""},b}(a.Block),a.LimitBlock=function(a){function b(a){b.__super__.constructor.call(this,a),this.limits=null}return k(b,a),b.prototype.limit=function(a){return a=this._sanitizeLimitOffset(a),this.limits=a},b.prototype.buildStr=function(){return this.limits?"LIMIT "+this.limits:""},b}(a.Block),a.JoinBlock=function(a){function b(a){b.__super__.constructor.call(this,a),this.joins=[]}return k(b,a),b.prototype.join=function(a,b,c,d){return null==b&&(b=null),null==c&&(c=null),null==d&&(d="INNER"),a=this._sanitizeTable(a,!0),b&&(b=this._sanitizeTableAlias(b)),c&&(c=this._sanitizeCondition(c)),this.joins.push({type:d,table:a,alias:b,condition:c}),this},b.prototype.left_join=function(a,b,c){return null==b&&(b=null),null==c&&(c=null),this.join(a,b,c,"LEFT")},b.prototype.right_join=function(a,b,c){return null==b&&(b=null),null==c&&(c=null),this.join(a,b,c,"RIGHT")},b.prototype.outer_join=function(a,b,c){return null==b&&(b=null),null==c&&(c=null),this.join(a,b,c,"OUTER")},b.prototype.buildStr=function(){var a,b,c,d,e;for(b="",e=this.joins||[],c=0,d=e.length;d>c;c++)a=e[c],""!==b&&(b+=" "),b+=""+a.type+" JOIN ",b+="string"==typeof a.table?a.table:"("+a.table+")",a.alias&&(b+=" "+a.alias),a.condition&&(b+=" ON ("+a.condition+")");return b},b}(a.Block),a.QueryBuilder=function(a){function b(a,c){var d,e,f,g,h,i,j,k,l=this;for(b.__super__.constructor.call(this,a),this.blocks=c||[],j=this.blocks,h=0,i=j.length;i>h;h++){d=j[h],k=d.exposedMethods(),g=function(a,b,c){return l[b]=function(){return c.apply(a,arguments),l}};for(f in k){if(e=k[f],null!=this[f])throw new Error(""+this._getObjectClassName(this)+" already has a builder method called: "+f);g(d,f,e)}}}return k(b,a),b.prototype.registerValueHandler=function(a,c){var d,e,f,g;for(g=this.blocks,e=0,f=g.length;f>e;e++)d=g[e],d.registerValueHandler(a,c);return b.__super__.registerValueHandler.call(this,a,c),this},b.prototype.updateOptions=function(a){var b,c,d,f,g;for(this.options=e({},this.options,a),f=this.blocks,g=[],c=0,d=f.length;d>c;c++)b=f[c],g.push(b.options=e({},b.options,a));return g},b.prototype.toString=function(){var a;return function(){var b,c,d,e;for(d=this.blocks,e=[],b=0,c=d.length;c>b;b++)a=d[b],e.push(a.buildStr(this));return e}.call(this).filter(function(a){return 0<a.length}).join(" ")},b.prototype.clone=function(){var a;return new this.constructor(this.options,function(){var b,c,d,e;for(d=this.blocks,e=[],b=0,c=d.length;c>b;b++)a=d[b],e.push(a.clone());return e}.call(this))},b.prototype.isNestable=function(){return!1},b}(a.BaseBuilder),a.Select=function(b){function c(b,d){null==d&&(d=null),d||(d=[new a.StringBlock(b,"SELECT"),new a.DistinctBlock(b),new a.GetFieldBlock(b),new a.FromTableBlock(e({},b,{allowNested:!0})),new a.JoinBlock(e({},b,{allowNested:!0})),new a.WhereBlock(b),new a.GroupByBlock(b),new a.OrderByBlock(b),new a.LimitBlock(b),new a.OffsetBlock(b)]),c.__super__.constructor.call(this,b,d)}return k(c,b),c.prototype.isNestable=function(){return!0},c}(a.QueryBuilder),a.Update=function(b){function c(b,d){null==d&&(d=null),d||(d=[new a.StringBlock(b,"UPDATE"),new a.UpdateTableBlock(b),new a.SetFieldBlock(b),new a.WhereBlock(b),new a.OrderByBlock(b),new a.LimitBlock(b)]),c.__super__.constructor.call(this,b,d)}return k(c,b),c}(a.QueryBuilder),a.Delete=function(b){function c(b,d){null==d&&(d=null),d||(d=[new a.StringBlock(b,"DELETE"),new a.FromTableBlock(e({},b,{singleTable:!0})),new a.JoinBlock(b),new a.WhereBlock(b),new a.OrderByBlock(b),new a.LimitBlock(b)]),c.__super__.constructor.call(this,b,d)}return k(c,b),c}(a.QueryBuilder),a.Insert=function(b){function c(b,d){null==d&&(d=null),d||(d=[new a.StringBlock(b,"INSERT"),new a.IntoTableBlock(b),new a.InsertFieldValueBlock(b)]),c.__super__.constructor.call(this,b,d)}return k(c,b),c}(a.QueryBuilder),d={expr:function(){return new a.Expression},select:function(b,c){return new a.Select(b,c)},update:function(b,c){return new a.Update(b,c)},insert:function(b,c){return new a.Insert(b,c)},"delete":function(b,c){return new a.Delete(b,c)},registerValueHandler:a.registerValueHandler},d.remove=d["delete"],d.cls=a,("undefined"!=typeof define&&null!==define?define.amd:void 0)?define(function(){return d}):("undefined"!=typeof module&&null!==module?module.exports:void 0)?module.exports=d:"undefined"!=typeof window&&null!==window&&(window.squel=d),d.flavours={},d.useFlavour=function(a){if(!(d.flavours[a]instanceof Function))throw new Error("Flavour not available: "+a);return d.flavours[a].call(null,d),d}}).call(this);
/*
Copyright (c) 2012-2013 Ramesh Nair (hiddentao.com)
Copyright (c) Ramesh Nair (hiddentao.com)

@@ -238,2 +238,6 @@ Permission is hereby granted, free of charge, to any person

BaseBuilder.prototype._escapeValue = function(str) {
return str;
};
BaseBuilder.prototype._formatValue = function(value) {

@@ -251,2 +255,3 @@ var customHandler;

if (false === this.options.usingValuePlaceholders) {
value = this._escapeValue(value);
value = "'" + value + "'";

@@ -1205,3 +1210,3 @@ }

/*
Copyright (c) 2012-2013 Ramesh Nair (hiddentao.com)
Copyright (c) Ramesh Nair (hiddentao.com)

@@ -1233,2 +1238,10 @@ Permission is hereby granted, free of charge, to any person

cls = squel.cls;
cls.DefaultQueryBuilderOptions.replaceSingleQuotes = false;
cls.DefaultQueryBuilderOptions.singleQuoteReplacement = '\'\'';
cls.BaseBuilder.prototype._escapeValue = function(value) {
if (true !== this.options.replaceSingleQuotes) {
return value;
}
return value.replace(/\'/g, this.options.singleQuoteReplacement);
};
cls.ReturningBlock = (function(_super) {

@@ -1273,2 +1286,98 @@ __extends(ReturningBlock, _super);

/*
Copyright (c) Ramesh Nair (hiddentao.com)
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
squel.flavours['mysql'] = function() {
cls = squel.cls;
return cls.InsertFieldValueBlock = (function(_super) {
__extends(InsertFieldValueBlock, _super);
function InsertFieldValueBlock(options) {
InsertFieldValueBlock.__super__.constructor.call(this, options);
this.fields = {};
this._duplicateKeyUpdates = {};
}
InsertFieldValueBlock.prototype.set = function(field, value, options) {
field = this._sanitizeField(field);
value = this._sanitizeValue(value);
this.fields[field] = value;
if ((options != null ? options.duplicateKeyUpdate : void 0) !== void 0) {
this._duplicateKeyUpdates[field] = this._sanitizeValue(options.duplicateKeyUpdate);
}
return this;
};
InsertFieldValueBlock.prototype.buildStr = function() {
var field, fieldNames, fields, name, str, value, values, _i, _len, _ref3;
fieldNames = (function() {
var _ref3, _results;
_ref3 = this.fields;
_results = [];
for (name in _ref3) {
if (!__hasProp.call(_ref3, name)) continue;
_results.push(name);
}
return _results;
}).call(this);
if (0 >= fieldNames.length) {
throw new Error("set() needs to be called");
}
fields = "";
values = "";
for (_i = 0, _len = fieldNames.length; _i < _len; _i++) {
field = fieldNames[_i];
if ("" !== fields) {
fields += ", ";
}
fields += field;
if ("" !== values) {
values += ", ";
}
values += this._formatValue(this.fields[field]);
}
str = "(" + fields + ") VALUES (" + values + ")";
fields = "";
_ref3 = this._duplicateKeyUpdates;
for (field in _ref3) {
value = _ref3[field];
if ("" !== fields) {
fields += ", ";
}
fields += "" + field + " = " + (this._formatValue(value));
}
if (fields !== "") {
str = "" + str + " ON DUPLICATE KEY UPDATE " + fields;
}
return str;
};
return InsertFieldValueBlock;
})(cls.SetFieldBlock);
};
}).call(this);
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