electrodb
Advanced tools
Comparing version 1.4.6 to 1.4.7
@@ -107,2 +107,9 @@ # Changelog | ||
### Added, Fixed | ||
- Adding Entity identifiers to all update operations. When primary index composite attributes were added in 1.4.4, entities were written properly but did not include the identifiers. This resulted in entities being written but not being readable without the query option `ignoreOwnership` being used. | ||
- Adding Entity identifiers to all update operations. When primary index composite attributes were added in 1.4.4, entities were written properly but did not include the identifiers. This resulted in entities being written but not being readable without the query option `ignoreOwnership` being used. | ||
## [1.4.7] = 2021-10-20 | ||
### Changed | ||
- Using `add()` update mutation now resolves to `ADD #prop :prop` update expression instead of a `SET #prop = #prop + :prop` | ||
### Fixed | ||
- Fixed param naming conflict during updates, when map attribute shares a name with another (separate) attribute. |
{ | ||
"name": "electrodb", | ||
"version": "1.4.6", | ||
"version": "1.4.7", | ||
"description": "A library to more easily create and interact with multiple entities and heretical relationships in dynamodb", | ||
@@ -14,3 +14,4 @@ "main": "index.js", | ||
"coverage-coveralls-local": "nyc npm run test-all-local && nyc report --reporter=text-lcov | coveralls", | ||
"coverage-html-local": "nyc npm run test-all-local && nyc report --reporter=html" | ||
"coverage-html-local": "nyc npm run test-all-local && nyc report --reporter=html", | ||
"build:browser": "browserify playground/browser.js -o playground/bundle.js" | ||
}, | ||
@@ -34,2 +35,3 @@ "repository": { | ||
"aws-sdk": "2.630.0", | ||
"browserify": "^17.0.0", | ||
"chai": "4.2.0", | ||
@@ -36,0 +38,0 @@ "coveralls": "^3.1.0", |
@@ -42,3 +42,3 @@ const e = require("./errors"); | ||
} | ||
let expression = template(attribute, prop, ...attrValues); | ||
let expression = template({}, attribute, prop, ...attrValues); | ||
return expression.trim(); | ||
@@ -45,0 +45,0 @@ }; |
@@ -7,3 +7,3 @@ const {AttributeTypes, ItemOperations, AttributeProxySymbol, BuilderTypes} = require("./types"); | ||
canNest: false, | ||
template: function del(attr, path, value) { | ||
template: function del(options, attr, path, value) { | ||
let operation = ""; | ||
@@ -27,3 +27,3 @@ let expression = ""; | ||
canNest: true, | ||
template: function name(attr, path) { | ||
template: function name(options, attr, path) { | ||
return path; | ||
@@ -34,3 +34,3 @@ } | ||
canNest: true, | ||
template: function value(attr, path, value) { | ||
template: function value(options, attr, path, value) { | ||
return value; | ||
@@ -41,3 +41,3 @@ } | ||
canNest: false, | ||
template: function append(attr, path, value) { | ||
template: function append(options, attr, path, value) { | ||
let operation = ""; | ||
@@ -59,3 +59,3 @@ let expression = ""; | ||
canNest: false, | ||
template: function add(attr, path, value) { | ||
template: function add(options, attr, path, value) { | ||
let operation = ""; | ||
@@ -70,4 +70,9 @@ let expression = ""; | ||
case AttributeTypes.number: | ||
operation = ItemOperations.set; | ||
expression = `${path} = ${path} + ${value}`; | ||
if (options.nestedValue) { | ||
operation = ItemOperations.set; | ||
expression = `${path} = ${path} + ${value}`; | ||
} else { | ||
operation = ItemOperations.add; | ||
expression = `${path} ${value}`; | ||
} | ||
break; | ||
@@ -82,3 +87,3 @@ default: | ||
canNest: false, | ||
template: function subtract(attr, path, value) { | ||
template: function subtract(options, attr, path, value) { | ||
let operation = ""; | ||
@@ -101,3 +106,3 @@ let expression = ""; | ||
canNest: false, | ||
template: function set(attr, path, value) { | ||
template: function set(options, attr, path, value) { | ||
let operation = ""; | ||
@@ -125,3 +130,3 @@ let expression = ""; | ||
canNest: false, | ||
template: function remove(attr, ...paths) { | ||
template: function remove(options, attr, ...paths) { | ||
let operation = ""; | ||
@@ -154,3 +159,3 @@ let expression = ""; | ||
ne: { | ||
template: function eq(attr, name, value) { | ||
template: function eq(options, attr, name, value) { | ||
return `${name} <> ${value}`; | ||
@@ -161,3 +166,3 @@ }, | ||
eq: { | ||
template: function eq(attr, name, value) { | ||
template: function eq(options, attr, name, value) { | ||
return `${name} = ${value}`; | ||
@@ -168,3 +173,3 @@ }, | ||
gt: { | ||
template: function gt(attr, name, value) { | ||
template: function gt(options, attr, name, value) { | ||
return `${name} > ${value}`; | ||
@@ -175,3 +180,3 @@ }, | ||
lt: { | ||
template: function lt(attr, name, value) { | ||
template: function lt(options, attr, name, value) { | ||
return `${name} < ${value}`; | ||
@@ -182,3 +187,3 @@ }, | ||
gte: { | ||
template: function gte(attr, name, value) { | ||
template: function gte(options, attr, name, value) { | ||
return `${name} >= ${value}`; | ||
@@ -189,3 +194,3 @@ }, | ||
lte: { | ||
template: function lte(attr, name, value) { | ||
template: function lte(options, attr, name, value) { | ||
return `${name} <= ${value}`; | ||
@@ -196,3 +201,3 @@ }, | ||
between: { | ||
template: function between(attr, name, value1, value2) { | ||
template: function between(options, attr, name, value1, value2) { | ||
return `(${name} between ${value1} and ${value2})`; | ||
@@ -203,3 +208,3 @@ }, | ||
begins: { | ||
template: function begins(attr, name, value) { | ||
template: function begins(options, attr, name, value) { | ||
return `begins_with(${name}, ${value})`; | ||
@@ -210,3 +215,3 @@ }, | ||
exists: { | ||
template: function exists(attr, name) { | ||
template: function exists(options, attr, name) { | ||
return `attribute_exists(${name})`; | ||
@@ -217,3 +222,3 @@ }, | ||
notExists: { | ||
template: function notExists(attr, name) { | ||
template: function notExists(options, attr, name) { | ||
return `attribute_not_exists(${name})`; | ||
@@ -224,3 +229,3 @@ }, | ||
contains: { | ||
template: function contains(attr, name, value) { | ||
template: function contains(options, attr, name, value) { | ||
return `contains(${name}, ${value})`; | ||
@@ -231,3 +236,3 @@ }, | ||
notContains: { | ||
template: function notContains(attr, name, value) { | ||
template: function notContains(options, attr, name, value) { | ||
return `not contains(${name}, ${value})`; | ||
@@ -238,3 +243,3 @@ }, | ||
value: { | ||
template: function(attr, name, value) { | ||
template: function(options, attr, name, value) { | ||
return value; | ||
@@ -246,3 +251,3 @@ }, | ||
name: { | ||
template: function(attr, name) { | ||
template: function(options, attr, name) { | ||
return name; | ||
@@ -256,3 +261,3 @@ }, | ||
class ExpressionState { | ||
constructor({prefix, singleOccurrence} = {}) { | ||
constructor({prefix} = {}) { | ||
this.names = {}; | ||
@@ -265,9 +270,5 @@ this.values = {}; | ||
this.prefix = prefix || ""; | ||
this.singleOccurrence = singleOccurrence; | ||
} | ||
incrementName(name) { | ||
if (this.singleOccurrence) { | ||
return `${this.prefix}${0}` | ||
} | ||
if (this.counts[name] === undefined) { | ||
@@ -400,8 +401,10 @@ this.counts[name] = 0; | ||
const attributeValues = []; | ||
let hasNestedValue = false; | ||
for (let value of values) { | ||
value = target.format(value); | ||
// template.length is to see if function takes value argument | ||
if (template.length > 2) { | ||
if (template.length > 3) { | ||
if (seen.has(value)) { | ||
attributeValues.push(value); | ||
hasNestedValue = true; | ||
} else { | ||
@@ -415,3 +418,7 @@ let attributeValueName = builder.setValue(target.name, value); | ||
const formatted = template(target, paths.expression, ...attributeValues); | ||
const options = { | ||
nestedValue: hasNestedValue | ||
} | ||
const formatted = template(options, target, paths.expression, ...attributeValues); | ||
builder.setImpacted(operation, paths.json); | ||
@@ -418,0 +425,0 @@ if (canNest) { |
@@ -6,3 +6,3 @@ const {AttributeOperationProxy, ExpressionState} = require("./operations"); | ||
constructor(props = {}) { | ||
super({...props, singleOccurrence: true}); | ||
super({...props}); | ||
this.operations = { | ||
@@ -9,0 +9,0 @@ set: new Set(), |
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
542935
7739
20