Repository: typedorm/typedorm (ts)

Issue:
Allow updating items with empty values for attributes
When trying to build update expression for attribute with falsy value, expression fails with "no value for given expression name"



Pull request description:
fix(core): allow updating attributes with undefined value
# Changes
- Allows updating attribute with undefined values 

closes #41 

Patch:
diff --git a/packages/core/src/classes/expression-builder.ts b/packages/core/src/classes/expression-builder.ts
index d27be22..5867ff4 100644
--- a/packages/core/src/classes/expression-builder.ts
+++ b/packages/core/src/classes/expression-builder.ts
@@ -59,7 +59,7 @@ export class ExpressionBuilder {
 
         const expValKey = `:val${index}`;
         acc.UpdateExpression += ` ${expAttrKey} = ${expValKey}`;
-        acc.ExpressionAttributeValues[expValKey] = item[key];
+        acc.ExpressionAttributeValues[expValKey] = item[key] ?? null;
         return acc;
       },
       {


Test patch:
diff --git a/packages/core/src/classes/__test__/expression-builder.spec.ts b/packages/core/src/classes/__test__/expression-builder.spec.ts
index f81e323..38635f2 100644
--- a/packages/core/src/classes/__test__/expression-builder.spec.ts
+++ b/packages/core/src/classes/__test__/expression-builder.spec.ts
@@ -87,3 +87,43 @@ test('builds update expression for complex nested object', () => {
     },
   });
 });
+
+/**
+ * Issue 41
+ */
+test('allows updating attribute with undefined value', () => {
+  const item = {
+    'user.name': undefined,
+  };
+  const expression = expressionBuilder.buildUpdateExpression(item);
+  expect(expression).toEqual({
+    UpdateExpression: 'SET #attr0_inner0.#attr0_inner1 = :val0',
+    ExpressionAttributeNames: {
+      '#attr0_inner0': 'user',
+      '#attr0_inner1': 'name',
+    },
+    ExpressionAttributeValues: {
+      ':val0': null,
+    },
+  });
+});
+
+/**
+ * Issue 41
+ */
+test('allows updating attribute with empty string', () => {
+  const item = {
+    'user.name': '',
+  };
+  const expression = expressionBuilder.buildUpdateExpression(item);
+  expect(expression).toEqual({
+    UpdateExpression: 'SET #attr0_inner0.#attr0_inner1 = :val0',
+    ExpressionAttributeNames: {
+      '#attr0_inner0': 'user',
+      '#attr0_inner1': 'name',
+    },
+    ExpressionAttributeValues: {
+      ':val0': '',
+    },
+  });
+});