mysql-query-builder-js
Advanced tools
Comparing version 0.0.3 to 0.0.5
103
index.js
@@ -32,5 +32,3 @@ /* | ||
this._fields = []; | ||
this._clausales = []; | ||
this.connectionTest = function(){ | ||
@@ -47,25 +45,6 @@ if(!this.connection){ | ||
} | ||
this.getWhere = function(){ | ||
if(this._clausales.length>0){ | ||
var str = " WHERE "; | ||
for(var i in this._clausales){ | ||
var cl = this._clausales[i]; | ||
if(i == 0){ | ||
str += cl.where; | ||
}else{ | ||
if(cl.type == 1){ | ||
str+=" AND "+cl.where; | ||
}else{ | ||
str+=" OR "+cl.where; | ||
} | ||
} | ||
} | ||
return str; | ||
}else{ | ||
return ''; | ||
} | ||
} | ||
} | ||
Builder.prototype = require('./src/where.js'); | ||
/** | ||
@@ -133,76 +112,2 @@ * Database connection | ||
/** | ||
* Where | ||
* @param {String|Array} params | ||
* @return {Object} this | ||
*/ | ||
Builder.prototype.where = function(param){ | ||
this.tableTest(); | ||
if(arguments.length > 1){ | ||
if(arguments.length > 2){ | ||
this._clausales.push({ | ||
type:1, | ||
where: arguments[0] + " " + arguments[1] + " '" + arguments[2] + "'" | ||
}); | ||
}else{ | ||
this._clausales.push({ | ||
type:1, | ||
where: arguments[0] + " = '" + arguments[1] + "'" | ||
}); | ||
} | ||
}else{ | ||
for(var i = 0 ; i < param.length; i++){ | ||
if(param[i].length > 2){ | ||
this._clausales.push({ | ||
type:1, | ||
where: param[i][0] + " " + param[i][1] + " '" + param[i][2] + "'" | ||
}); | ||
}else{ | ||
this._clausales.push({ | ||
type:1, | ||
where: param[i][0] + " = '" + param[i][1] + "'" | ||
}); | ||
} | ||
} | ||
} | ||
return this; | ||
} | ||
/** | ||
* Where Or | ||
* @param {String|Array} params | ||
* @return {Object} this | ||
*/ | ||
Builder.prototype.whereOr = function(param){ | ||
this.tableTest(); | ||
if(arguments.length > 1){ | ||
if(arguments.length > 2){ | ||
this._clausales.push({ | ||
type:2, | ||
where: arguments[0] + " " + arguments[1] + " '" + arguments[2] + "'" | ||
}); | ||
}else{ | ||
this._clausales.push({ | ||
type:2, | ||
where: arguments[0] + " = '" + arguments[1] + "'" | ||
}); | ||
} | ||
}else{ | ||
for(var i = 0 ; i < param.length; i++){ | ||
if(param[i].length > 2){ | ||
this._clausales.push({ | ||
type:2, | ||
where: param[i][0] + " " + param[i][1] + " '" + param[i][2] + "'" | ||
}); | ||
}else{ | ||
this._clausales.push({ | ||
type:2, | ||
where: param[i][0] + " = '" + param[i][1] + "'" | ||
}); | ||
} | ||
} | ||
} | ||
return this; | ||
} | ||
/** | ||
* Get query result | ||
@@ -214,2 +119,5 @@ * | ||
Builder.prototype.get = function(callback){ | ||
this.connectionTest(); | ||
this.tableTest(); | ||
this._fields = (this._fields.length>0)?this._fields:['*']; | ||
this.sql = "SELECT "+this._fields.join(',')+" FROM "+this._table+this.getWhere(); | ||
@@ -224,2 +132,3 @@ | ||
module.exports = new Builder(); |
{ | ||
"name": "mysql-query-builder-js", | ||
"version": "0.0.3", | ||
"version": "0.0.5", | ||
"description": "Query builder for mysql in Node.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -11,8 +11,9 @@ var builder = require('../index'); | ||
builder.table('pessoas') | ||
.select('nome','email') | ||
.where('id','>',1) | ||
.whereOr('email','like','%jay%') | ||
.whereNotIn('id',[1,2]) | ||
.get(function(err, rows, fields, sql){ | ||
console.log(sql) | ||
if(err){ | ||
console.log(err) | ||
} | ||
console.log(rows) | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10137
7
317
1