sqlquerybuilder
Advanced tools
Comparing version 0.0.19 to 0.0.20
@@ -28,6 +28,8 @@ module.exports = function selects(self) { | ||
self.select = function select(sel) { | ||
if(!self._sqlObject.select)self._sqlObject.select=""; | ||
else self._sqlObject.select+=", "; | ||
if (typeof(sel) == 'string') { | ||
self._sqlObject.select = sel; | ||
self._sqlObject.select += sel; | ||
} else if (sel instanceof Array) { | ||
self._sqlObject.select = ""; | ||
self._sqlObject.select += ""; | ||
for (var a = 0; a < sel.length; a++) { | ||
@@ -38,3 +40,3 @@ self._sqlObject.select += sel[a]; | ||
} else if (sel instanceof Object) { | ||
self._sqlObject.select = ""; | ||
self._sqlObject.select += ""; | ||
var props = Object.keys(sel); | ||
@@ -65,4 +67,5 @@ for (var i = 0; i < props.length; i++) { | ||
self.selectJoin = function selectJoin(selObj) { | ||
if(!self._sqlObject.select)self._sqlObject.select=""; | ||
else self._sqlObject.select+=", "; | ||
if (selObj instanceof Object) { | ||
self._sqlObject.select = ""; | ||
var props = Object.keys(selObj); | ||
@@ -69,0 +72,0 @@ for (var i = 0; i < props.length; i++) { |
{ | ||
"name": "sqlquerybuilder", | ||
"version": "0.0.19", | ||
"version": "0.0.20", | ||
"description": "Highly opinionated Sql Server Query Writer, mostly for internal use.", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index", |
@@ -75,4 +75,21 @@ /** | ||
}); | ||
it('should chain selects', function(done){ | ||
sqlBuilder().from('main') | ||
.selectJoin({'main.Id':'Id', 'secondary.Id': 'secondary.Id'}) | ||
.join("tertiary") | ||
.select({'tertiary.Property': 'Prop'}) | ||
.build().should.equal("SELECT main.Id AS 'Id', secondary.Id AS 'secondary.Id', tertiary.Property AS 'Prop' FROM main " + | ||
"JOIN secondary ON main.secondary_id = secondary.Id JOIN tertiary ON main.tertiary_id = tertiary.Id "); | ||
done(); | ||
}); | ||
it('should chain selects', function(done){ | ||
sqlBuilder().from('main') | ||
.join("tertiary") | ||
.select({'tertiary.Property': 'Prop'}) | ||
.selectJoin({'main.Id':'Id', 'secondary.Id': 'secondary.Id'}) | ||
.build().should.equal("SELECT tertiary.Property AS 'Prop', main.Id AS 'Id', secondary.Id AS 'secondary.Id' FROM main " + | ||
"JOIN tertiary ON main.tertiary_id = tertiary.Id JOIN secondary ON main.secondary_id = secondary.Id "); | ||
done(); | ||
}); | ||
}); | ||
@@ -150,2 +167,3 @@ | ||
}); | ||
}); |
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
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
172927
3684