dynamodb-builder
Advanced tools
Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "dynamodb-builder", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Dynamodb builder", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -53,2 +53,3 @@ "use strict"; | ||
let item = obj[key]; | ||
let temp = undefined; | ||
let hasNotOperator = this.hasNotOperator(key); | ||
@@ -65,10 +66,19 @@ if (hasNotOperator) { | ||
let type = this.getTypeOfValue(key, item); | ||
arrayConditions.push(this.expressionObjToString(type, prefix)); | ||
temp = this.expressionObjToString(type, prefix); | ||
if (temp) { | ||
arrayConditions.push(temp); | ||
} | ||
} else if (typeof item == "object" && !this.hasOperator(key)) { | ||
this.attributesNames[this.toAttributeName(key)] = key; | ||
let new_prefix = prefix + this.toAttributeName(key) + "."; | ||
arrayConditions.push(this.formatRec(item, new_prefix).str); | ||
temp = this.formatRec(item, new_prefix).str; | ||
if (temp) { | ||
this.attributesNames[this.toAttributeName(key)] = key; | ||
arrayConditions.push(temp); | ||
} | ||
} else if (typeof item == "object" && this.hasOperator(key)) { | ||
let type = this.getTypeOfValue(key, item); | ||
arrayConditions.push(this.expressionObjToString(type, prefix)); | ||
temp = this.expressionObjToString(type, prefix); | ||
if (temp) { | ||
arrayConditions.push(temp); | ||
} | ||
} else { | ||
@@ -81,3 +91,7 @@ let type = this.getTypeOfValue(key, item); | ||
}); | ||
this.str = arrayConditions.join(" " + operator + " "); | ||
this.str = arrayConditions | ||
.filter(v => { | ||
return v; | ||
}) | ||
.join(" " + operator + " "); | ||
@@ -92,18 +106,26 @@ return this; | ||
}); | ||
let str = arrayConditions.join(" " + OR_OPERATOR + " "); | ||
return "(" + str + ")"; | ||
let str = arrayConditions | ||
.filter(v => { | ||
return v; | ||
}) | ||
.join(" " + OR_OPERATOR + " "); | ||
return str ? "(" + str + ")" : ""; | ||
} | ||
inOperation(key, array, prefix) { | ||
let inValues = []; | ||
this.attributesNames[this.toAttributeName(key)] = key; | ||
array.forEach(value => { | ||
this.attributesValues[this.toAttributeValue(iteratorValue)] = value; | ||
inValues.push(this.toAttributeValue(iteratorValue)); | ||
this.incIteratorValue(); | ||
}); | ||
if (array.length > 0) { | ||
let inValues = []; | ||
this.attributesNames[this.toAttributeName(key)] = key; | ||
array.forEach(value => { | ||
this.attributesValues[this.toAttributeValue(iteratorValue)] = value; | ||
inValues.push(this.toAttributeValue(iteratorValue)); | ||
this.incIteratorValue(); | ||
}); | ||
let str = inValues.join(","); | ||
let str = inValues.join(","); | ||
return "(" + prefix + this.toAttributeName(key) + " IN (" + str + "))"; | ||
return "(" + prefix + this.toAttributeName(key) + " IN (" + str + "))"; | ||
} else { | ||
return ""; | ||
} | ||
} | ||
@@ -110,0 +132,0 @@ |
@@ -61,3 +61,3 @@ const DynamoDBExpressionBuilder = require("../src/DynamoDBExpressionBuilder"); | ||
describe("($OR) ($IS)", function() { | ||
it("11.", function() { | ||
it("1.", function() { | ||
let filter = { | ||
@@ -71,3 +71,3 @@ faa: { | ||
}); | ||
it("12.", function() { | ||
it("2.", function() { | ||
let filter = { | ||
@@ -79,3 +79,3 @@ "($OR)": [{ "foo ($IS) ": "bar", fuu: "foo" }, { "foo ($IS) ": "fee", fuu: "poo" }] | ||
}); | ||
it("13.", function() { | ||
it("3.", function() { | ||
let filter = { | ||
@@ -88,3 +88,3 @@ "($OR)": [{ "foo ($IS) ": "bar", fuu: "foo" }, { "foo ($IS) ": "fee", fuu: "poo" }], | ||
}); | ||
it("14.", function() { | ||
it("4.", function() { | ||
let filter = { | ||
@@ -97,3 +97,3 @@ gee: "ree", | ||
}); | ||
it("15.", function() { | ||
it("5.", function() { | ||
let filter = { | ||
@@ -108,3 +108,3 @@ faa: { | ||
}); | ||
it("16.", function() { | ||
it("6.", function() { | ||
let filter = { | ||
@@ -122,2 +122,18 @@ faa: { | ||
}); | ||
it("7.", function() { | ||
let filter = { | ||
gee: "ree", | ||
"($OR)": [] | ||
}; | ||
let DDBExprParser = new DynamoDBExpressionBuilder(filter); | ||
DDBExprParser.debug().should.equal("#gee = ree"); | ||
}); | ||
it("8.", function() { | ||
let filter = { | ||
gee: "ree", | ||
fee: { lee: { "($OR)": [] } } | ||
}; | ||
let DDBExprParser = new DynamoDBExpressionBuilder(filter); | ||
DDBExprParser.debug().should.equal("#gee = ree"); | ||
}); | ||
}); | ||
@@ -194,2 +210,7 @@ | ||
}); | ||
it("4.", function() { | ||
let filter = { feee: "tre", faa: { "foo ($IN)": [] }, gee: "oui" }; | ||
let DDBExprParser = new DynamoDBExpressionBuilder(filter); | ||
DDBExprParser.debug().should.equal("#feee = tre AND #gee = oui"); | ||
}); | ||
}); | ||
@@ -196,0 +217,0 @@ |
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
23751
529