Skip to content

Commit bbdb9ae

Browse files
committed
Revert "Skipping empty string in update expressions as it used to convert to … (adjoeio#28)"
This reverts commit 7fec125.
1 parent a7c61bf commit bbdb9ae

4 files changed

Lines changed: 0 additions & 149 deletions

File tree

dynamo_repository.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,6 @@ func (repository Repository) UpdateWithContext(ctx context.Context, expression U
109109
}
110110

111111
for expr, value := range values {
112-
if isEmptyString(value) {
113-
continue
114-
}
115112
if expression == Add {
116113
update.Add(expr, value)
117114
}
@@ -162,9 +159,6 @@ func (repository Repository) prepareUpdateWithUpdateExpressions(
162159
expression := UpdateExpression(updateExpression)
163160

164161
for expr, value := range v {
165-
if isEmptyString(value) {
166-
continue
167-
}
168162
if expression == Add {
169163
update.Add(expr, value)
170164
}

helper.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ func valueFromPtr[T any](ptr *T) T {
1313
return *ptr
1414
}
1515

16-
func isEmptyString(value any) bool {
17-
str, ok := value.(string)
18-
return ok && str == ""
19-
}
20-
2116
func buildTableKeyCondition(table dynamo.Table, key KeyInterface) *dynamo.Query {
2217
q := table.Get(*key.HashKeyName(), key.HashKey())
2318

key.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,5 @@ func isValidHashKey(key KeyInterface) error {
100100
if key.HashKey() == nil {
101101
return ErrInvalidHashKeyValue
102102
}
103-
if str, ok := key.HashKey().(string); ok && str == "" {
104-
return ErrInvalidHashKeyValue
105-
}
106103
return nil
107104
}

repository_update_test.go

Lines changed: 0 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,6 @@ var _ = Describe("Repository", func() {
6767
"TraceID": "name4",
6868
}
6969

70-
err := repository.UpdateWithContext(context.Background(), djoemo.Set, key, updates)
71-
Expect(err).To(Equal(djoemo.ErrInvalidHashKeyValue))
72-
})
73-
It("should fail with hash key value is empty string", func() {
74-
key := djoemo.Key().WithTableName(UserTableName).WithHashKeyName("UUID").WithHashKey("")
75-
metricsMock.EXPECT().Record(gomock.Any(), djoemo.OpUpdate, key, gomock.Any(), false)
76-
updates := map[string]interface{}{
77-
"UserName": "name2",
78-
"TraceID": "name4",
79-
}
80-
8170
err := repository.UpdateWithContext(context.Background(), djoemo.Set, key, updates)
8271
Expect(err).To(Equal(djoemo.ErrInvalidHashKeyValue))
8372
})
@@ -109,54 +98,6 @@ var _ = Describe("Repository", func() {
10998
Expect(err).To(BeNil())
11099
})
111100

112-
It("should skip empty string values in Set update", func() {
113-
key := djoemo.Key().WithTableName(UserTableName).
114-
WithHashKeyName("UUID").
115-
WithHashKey("uuid")
116-
117-
dMock.Should().Update(
118-
dMock.WithTable(key.TableName()),
119-
dMock.WithMatch(
120-
mock.InputExpect().
121-
FieldEq("UserName", "name2"),
122-
),
123-
).Exec()
124-
125-
metricsMock.EXPECT().Record(gomock.Any(), djoemo.OpUpdate, key, gomock.Any(), true)
126-
127-
updates := map[string]interface{}{
128-
"UserName": "name2",
129-
"DeviceID": "",
130-
}
131-
132-
err := repository.UpdateWithContext(context.Background(), djoemo.Set, key, updates)
133-
Expect(err).To(BeNil())
134-
})
135-
136-
It("should skip empty string values in SetIfNotExists update", func() {
137-
key := djoemo.Key().WithTableName(UserTableName).
138-
WithHashKeyName("UUID").
139-
WithHashKey("uuid")
140-
141-
dMock.Should().Update(
142-
dMock.WithTable(key.TableName()),
143-
dMock.WithMatch(
144-
mock.InputExpect().
145-
FieldEq("SDKHash", "hash123"),
146-
),
147-
).Exec()
148-
149-
metricsMock.EXPECT().Record(gomock.Any(), djoemo.OpUpdate, key, gomock.Any(), true)
150-
151-
updates := map[string]interface{}{
152-
"SDKHash": "hash123",
153-
"DeviceName": "",
154-
}
155-
156-
err := repository.UpdateWithContext(context.Background(), djoemo.SetIfNotExists, key, updates)
157-
Expect(err).To(BeNil())
158-
})
159-
160101
It("should Update item with SetSet", func() {
161102
key := djoemo.Key().WithTableName(UserTableName).
162103
WithHashKeyName("UUID").
@@ -274,82 +215,6 @@ var _ = Describe("Repository", func() {
274215
})
275216
})
276217

277-
Describe("UpdateWithUpdateExpressions", func() {
278-
It("should update item with mixed Set and SetIfNotExists expressions", func() {
279-
key := djoemo.Key().WithTableName(UserTableName).
280-
WithHashKeyName("UUID").
281-
WithHashKey("uuid")
282-
283-
dMock.Should().Update(
284-
dMock.WithTable(key.TableName()),
285-
dMock.WithMatch(
286-
mock.InputExpect().
287-
FieldEq("UserName", "name2").FieldEq("SDKHash", "hash123"),
288-
),
289-
).Exec()
290-
291-
metricsMock.EXPECT().Record(gomock.Any(), djoemo.OpUpdate, key, gomock.Any(), true)
292-
293-
updateExpressions := djoemo.UpdateExpressions{
294-
djoemo.Set: {
295-
"UserName": "name2",
296-
},
297-
djoemo.SetIfNotExists: {
298-
"SDKHash": "hash123",
299-
},
300-
}
301-
302-
err := repository.UpdateWithUpdateExpressions(context.Background(), key, updateExpressions)
303-
Expect(err).To(BeNil())
304-
})
305-
306-
It("should fail with hash key value is empty string", func() {
307-
key := djoemo.Key().WithTableName(UserTableName).WithHashKeyName("UUID").WithHashKey("")
308-
metricsMock.EXPECT().Record(gomock.Any(), djoemo.OpUpdate, key, gomock.Any(), false)
309-
310-
updateExpressions := djoemo.UpdateExpressions{
311-
djoemo.Set: {
312-
"UserName": "name2",
313-
},
314-
}
315-
316-
err := repository.UpdateWithUpdateExpressions(context.Background(), key, updateExpressions)
317-
Expect(err).To(Equal(djoemo.ErrInvalidHashKeyValue))
318-
})
319-
320-
It("should skip empty string values in Set and SetIfNotExists expressions", func() {
321-
key := djoemo.Key().WithTableName(UserTableName).
322-
WithHashKeyName("UUID").
323-
WithHashKey("uuid")
324-
325-
dMock.Should().Update(
326-
dMock.WithTable(key.TableName()),
327-
dMock.WithMatch(
328-
mock.InputExpect().
329-
FieldEq("UserName", "name2").FieldEq("SDKHash", "hash123"),
330-
),
331-
).Exec()
332-
333-
metricsMock.EXPECT().Record(gomock.Any(), djoemo.OpUpdate, key, gomock.Any(), true)
334-
335-
updateExpressions := djoemo.UpdateExpressions{
336-
djoemo.Set: {
337-
"UserName": "name2",
338-
"DeviceID": "",
339-
"ProductName": "",
340-
},
341-
djoemo.SetIfNotExists: {
342-
"SDKHash": "hash123",
343-
"DeviceName": "",
344-
"DeviceType": "",
345-
},
346-
}
347-
348-
err := repository.UpdateWithUpdateExpressions(context.Background(), key, updateExpressions)
349-
Expect(err).To(BeNil())
350-
})
351-
})
352-
353218
Describe("UpdateItem with condition", func() {
354219
It("should save an item if the condition is met", func() {
355220
key := djoemo.Key().WithTableName(UserTableName).

0 commit comments

Comments
 (0)