Comparing version 0.6.3 to 0.6.4
(function(exports) { | ||
"use strict"; | ||
var opt = {}; | ||
function monologue(opt) { | ||
return new Monologue(opt); | ||
} | ||
function monologue(options) { | ||
function Monologue(opt) { | ||
// default values | ||
this.opt = {}; | ||
var dict = { escape: true, backquote: true, sort_keys: false }; | ||
if( typeof options === "undefined" ) { | ||
opt = dict; | ||
if( typeof opt === "undefined" ) { | ||
this.opt = dict; | ||
} | ||
@@ -16,12 +20,10 @@ | ||
for( var i in dict ) { | ||
opt[i] = ( typeof options[i] === "undefined" ? dict[i] : options[i] ); | ||
this.opt[i] = ( typeof opt[i] === "undefined" ? dict[i] : opt[i] ); | ||
} | ||
} | ||
return new Monologue(); | ||
} | ||
function Monologue() { | ||
this.sql = ''; | ||
this.parts = {}; | ||
// store whether where() or having() was used last | ||
@@ -60,3 +62,3 @@ // (I hope this doesn't get ugly) | ||
Monologue.prototype.select = function select( col, tbl ) { | ||
if( opt.backquote ) { | ||
if( this.opt.backquote ) { | ||
tbl = this.backquote(tbl); | ||
@@ -89,3 +91,3 @@ | ||
if( opt.backquote ) { | ||
if( this.opt.backquote ) { | ||
tbl = this.backquote(tbl); | ||
@@ -95,3 +97,3 @@ } | ||
if( typeof stmt === "object" ) { | ||
if( opt.backquote ) { | ||
if( this.opt.backquote ) { | ||
stmt = this.backquote(stmt); | ||
@@ -121,3 +123,3 @@ } | ||
if( opt.backquote ) { | ||
if( this.opt.backquote ) { | ||
tbl = this.backquote(tbl); | ||
@@ -154,3 +156,3 @@ } | ||
if( opt.backquote ) { | ||
if( this.opt.backquote ) { | ||
tbl = this.backquote(tbl); | ||
@@ -177,3 +179,3 @@ } | ||
Monologue.prototype.delete = function _delete( tbl, wh ) { | ||
if( opt.backquote ) { | ||
if( this.opt.backquote ) { | ||
tbl = this.backquote(tbl); | ||
@@ -229,3 +231,3 @@ } | ||
Monologue.prototype.like = function like( like ) { | ||
if( opt.escape ) { | ||
if( this.opt.escape ) { | ||
like = this.escape(like); | ||
@@ -242,3 +244,3 @@ } | ||
Monologue.prototype.between = function between( one, two ) { | ||
if( opt.escape ) { | ||
if( this.opt.escape ) { | ||
one = this.escape(one); | ||
@@ -258,3 +260,3 @@ two = this.escape(two); | ||
if( opt.backquote ) { | ||
if( this.opt.backquote ) { | ||
grp = this.backquote(grp); | ||
@@ -321,3 +323,3 @@ } | ||
if( opt.backquote ) { | ||
if( this.opt.backquote ) { | ||
ord = this.backquote(ord); | ||
@@ -348,3 +350,3 @@ } | ||
Monologue.prototype.union = function union( c, t ) { | ||
if( opt.backquote ) { | ||
if( this.opt.backquote ) { | ||
t = this.backquote(t); | ||
@@ -499,3 +501,3 @@ | ||
if( opt.sort_keys ) | ||
if( this.opt.sort_keys ) | ||
this.parts.columns.sort(); | ||
@@ -505,3 +507,3 @@ | ||
// so do it here, if applicable | ||
var cols = ( opt.backquote | ||
var cols = ( this.opt.backquote | ||
? this.backquote( this.parts.columns ) | ||
@@ -528,3 +530,3 @@ : this.parts.columns ); | ||
if( this.parts.columns.length === 0 ) { | ||
var col = ( opt.sort_keys | ||
var col = ( this.opt.sort_keys | ||
? Object.keys(p).sort() | ||
@@ -558,3 +560,3 @@ : Object.keys(p) ); | ||
var ret = ( opt.backquote && k ? this.backquote( k ) : k ) | ||
var ret = ( this.opt.backquote && k ? this.backquote( k ) : k ) | ||
+ " IN (" + vs + ")"; | ||
@@ -586,7 +588,7 @@ | ||
else { | ||
if( opt.escape ) { | ||
if( this.opt.escape ) { | ||
v = this.escape(v); | ||
} | ||
if( k && opt.backquote ) { | ||
if( k && this.opt.backquote ) { | ||
k = this.backquote(k); | ||
@@ -593,0 +595,0 @@ |
{ | ||
"name": "monologue", | ||
"version": "0.6.3", | ||
"version": "0.6.4", | ||
"description": "Streamlined MySQL query building", | ||
@@ -5,0 +5,0 @@ "main": "./monologue.js", |
56500
491