Skip to content

Commit

Permalink
feat: expression attribute values by types (#49)
Browse files Browse the repository at this point in the history
* make values of different types to be encoded separately.

* make values of different types to be encoded separately.
  • Loading branch information
togashi committed Mar 14, 2023
1 parent d5bcf9e commit 46d5aef
Show file tree
Hide file tree
Showing 15 changed files with 564 additions and 565 deletions.
103 changes: 51 additions & 52 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ const params = dynoexpr({

/*
{
KeyConditionExpression: '(#n75a60c8f = :v64c5aa3d)',
ExpressionAttributeValues: {
':v64c5aa3d': '567',
':va7bbf170': 4.5,
':v91380c8f': 'blue'
KeyConditionExpression: '(#nca40fdf5 = :v8dcca6b2)',
ExpressionAttributeValues: {
':v8dcca6b2': '567',
':vc95fafc8': 4.5,
':v792aabee': 'blue'
},
ConditionExpression: '(#n8793843d > :va7bbf170)',
FilterExpression: '(#n4bce9bfd = :v91380c8f)',
ProjectionExpression: '#nf337db8f,#n395c1a24',
ConditionExpression: '(#n0f1c2905 > :vc95fafc8)',
FilterExpression: '(#n2d334799 = :v792aabee)',
ProjectionExpression: '#neb86488e,#n0367c420',
ExpressionAttributeNames: {
'#n75a60c8f': 'id',
'#n8793843d': 'rating',
'#n4bce9bfd': 'color',
'#nf337db8f': 'weight',
'#n395c1a24': 'size'
'#nca40fdf5': 'id',
'#n0f1c2905': 'rating',
'#n2d334799': 'color',
'#neb86488e': 'weight',
'#n0367c420': 'size'
}
}
*/
Expand Down Expand Up @@ -95,13 +95,13 @@ const params = dynoexpr({

/*
{
ConditionExpression: '(attribute_not_exists(#n4bce9bfd)) OR (#n4bce9bfd = :vaeafa351) OR (#n4bce9bfd = :v91380c8f)',
ExpressionAttributeNames: {
'#n4bce9bfd': 'color'
ConditionExpression: '(attribute_not_exists(#n2d334799)) OR (#n2d334799 = :v0d81c8cd) OR (#n2d334799 = :v792aabee)',
ExpressionAttributeNames: {
'#n2d334799': 'color'
},
ExpressionAttributeValues: {
':vaeafa351': 'yellow',
':v91380c8f': 'blue'
':v0d81c8cd': 'yellow',
':v792aabee': 'blue'
}
}
*/
Expand All @@ -125,21 +125,20 @@ const params = dynoexpr({

/*
{
ConditionExpression: '(attribute_exists(#n3f51d286)) AND (attribute_not_exists(#n51fd0ed7)) AND (attribute_type(#n12a7a4d6,:v0824ec29)) AND (begins_with(#n4bce9bfd,:v372ebe37)) AND (contains(#n9ad2536a,:vb3b07bff)) AND (size(#n8fcb2786) < :v106a3b84)',
ConditionExpression: '(attribute_exists(#nd0a55266)) AND (attribute_not_exists(#n4e5f8507)) AND (attribute_type(#n4a177797,:v64b0a475)) AND (begins_with(#n2d334799,:v1fdc3f67)) AND (contains(#n3af77f77,:v26425a2a)) AND (size(#nb6c8f268) < :vde9019e3)',
ExpressionAttributeNames: {
'#n3f51d286': 'docs',
'#n51fd0ed7': 'brand',
'#n12a7a4d6': 'extra',
'#n4bce9bfd': 'color',
'#n9ad2536a': 'address',
'#n8fcb2786': 'description'
'#nd0a55266': 'docs',
'#n4e5f8507': 'brand',
'#n4a177797': 'extra',
'#n2d334799': 'color',
'#n3af77f77': 'address',
'#nb6c8f268': 'description'
},
ExpressionAttributeValues: {
':v0824ec29': 'NULL',
':v372ebe37': 'dark',
':vb3b07bff': 'Seattle',
':v106a3b84': 20
}
':v64b0a475': 'NULL',
':v1fdc3f67': 'dark',
':v26425a2a': 'Seattle',
':vde9019e3': 20
}
}
*/
Expand All @@ -155,15 +154,15 @@ const params = dynoexpr({

/*
{
ConditionExpression: '(#n0a01a3d5 < :ve770c6dd)',
ExpressionAttributeNames: {
'#n0a01a3d5': 'Sum'
ConditionExpression: '(#n5af617ef < :va88c83b0)',
ExpressionAttributeNames: {
'#n5af617ef': 'Sum'
},
ExpressionAttributeValues: {
':ve770c6dd': 100,
':v106a3b84': 20
ExpressionAttributeValues: {
':va88c83b0': 100,
':vde9019e3': 20
},
UpdateExpression: 'SET #n0a01a3d5 = #n0a01a3d5 + :v106a3b84'
UpdateExpression: 'SET #n5af617ef = #n5af617ef + :vde9019e3'
}
*/
```
Expand All @@ -184,9 +183,9 @@ const params = dynoexpr({

/*
{
UpdateExpression: 'SET #ndc9f7295 = :v3add0a80',
ExpressionAttributeNames: {
'#ndc9f7295': 'Color'
UpdateExpression: 'SET #n8979552b = :v3add0a80',
ExpressionAttributeNames: {
'#n8979552b': 'Color'
},
ExpressionAttributeValues: {
':v3add0a80': Set { wrapperName: 'Set', values: [Array], type: 'String' }
Expand Down Expand Up @@ -236,11 +235,11 @@ const params = dynoexpr({
ProjectionExpression: '#year',
ExpressionAttributeNames: {
'#year': 'year',
'#n4bce9bfd': 'color'
'#n2d334799': 'color'
},
FilterExpression: '(#n4bce9bfd = :v91380c8f)',
FilterExpression: '(#n2d334799 = :v792aabee)',
ExpressionAttributeValues: {
':v91380c8f': 'blue'
':v792aabee': 'blue'
}
}
*/
Expand All @@ -265,12 +264,12 @@ const params = dynoexpr({
TableName: 'Table',
Key: { HashKey: 'key' },
ReturnConsumedCapacity: 'TOTAL',
KeyConditionExpression: '(begins_with(#n4bce9bfd,:v372ebe37))',
KeyConditionExpression: '(begins_with(#n2d334799,:v1fdc3f67))',
ExpressionAttributeNames: {
'#n4bce9bfd': 'color'
'#n2d334799': 'color'
},
ExpressionAttributeValues: {
':v372ebe37': 'dark'
':v1fdc3f67': 'dark'
}
}
*/
Expand All @@ -294,10 +293,10 @@ const params = dynoexpr({
"RequestItems":{
"Table-1":{
"Keys": [{"foo":"bar"}],
"ProjectionExpression": "#n69772661,#n7531578f",
"ProjectionExpression": "#na0f0d7ff,#ne4645342",
"ExpressionAttributeNames":{
"#n69772661": "a",
"#n7531578f": "b"
"#na0f0d7ff": "a",
"#ne4645342": "b"
}
}
},
Expand Down Expand Up @@ -327,10 +326,10 @@ const params = dynoexpr({
"Get": {
"TableName": "Table-1",
"Key": { "id": "foo" },
"ProjectionExpression": "#n69772661,#n7531578f",
"ProjectionExpression": "#na0f0d7ff,#ne4645342",
"ExpressionAttributeNames": {
"#n69772661":"a",
"#n7531578f":"b"
"#na0f0d7ff":"a",
"#ne4645342":"b"
}
}
}
Expand Down
56 changes: 28 additions & 28 deletions src/bug-reports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ describe("bug reports", () => {

const expected = {
ConditionExpression:
"(#n44ec6258 = :va87bccc9) OR (#n44ec6258 = :v5ebbf5c3)",
"(#nfc6b756c = :v84e520b4) OR (#nfc6b756c = :ve0304017)",
ExpressionAttributeNames: {
"#n4b532461": "GSI1_PK",
"#n44ec6258": "status",
"#n4a4b98d5": "modified",
"#nfbaeecf8": "GSI2_PK",
"#n3974b0c4": "GSI1_PK",
"#nfc6b756c": "status",
"#n93dbb70d": "modified",
"#n87f01ccc": "GSI2_PK",
},
ExpressionAttributeValues: {
":vd8444872": "2022-03-02T19:33:14.000Z",
":v879a6e2b": "REQUEST#STATUS#open#DATE#2022-03-01T13:58:09.242z",
":va87bccc9": "IN_PROGRESS",
":v5ebbf5c3": "OPEN",
":vb60424a8": "2022-03-02T19:33:14.000Z",
":v985d200a": "REQUEST#STATUS#open#DATE#2022-03-01T13:58:09.242z",
":v84e520b4": "IN_PROGRESS",
":ve0304017": "OPEN",
},
UpdateExpression:
"SET #n4a4b98d5 = :vd8444872, #n4b532461 = :v5ebbf5c3, #nfbaeecf8 = :v879a6e2b",
"SET #n93dbb70d = :vb60424a8, #n3974b0c4 = :ve0304017, #n87f01ccc = :v985d200a",
};
expect(actual).toStrictEqual(expected);

Expand All @@ -49,9 +49,9 @@ describe("bug reports", () => {

const expected = {
UpdateExpression:
"SET #ne68615df = if_not_exists(#ne68615df, :v24592772)",
ExpressionAttributeNames: { "#ne68615df": "number" },
ExpressionAttributeValues: { ":v24592772": "420" },
"SET #nc66bcf16 = if_not_exists(#nc66bcf16, :v70d78b9d)",
ExpressionAttributeNames: { "#nc66bcf16": "number" },
ExpressionAttributeValues: { ":v70d78b9d": "420" },
};
expect(actual).toStrictEqual(expected);
});
Expand All @@ -65,10 +65,10 @@ describe("bug reports", () => {
const actual = dynoexpr(args);

const expected = {
ExpressionAttributeNames: { "#n69772661": "a", "#n7531578f": "b" },
ExpressionAttributeValues: { ":v05902327": false, ":v7534cb09": true },
ExpressionAttributeNames: { "#na0f0d7ff": "a", "#ne4645342": "b" },
ExpressionAttributeValues: { ":v976fa742": false, ":vc86ac629": true },
FilterExpression:
"(#n69772661 <> :v7534cb09) AND (#n7531578f <> :v05902327)",
"(#na0f0d7ff <> :vc86ac629) AND (#ne4645342 <> :v976fa742)",
};
expect(actual).toStrictEqual(expected);
});
Expand All @@ -81,12 +81,12 @@ describe("bug reports", () => {
const actual = dynoexpr(args);

const expected = {
ConditionExpression: "(attribute_exists(#n7e86b602.#n95d67ebc))",
ConditionExpression: "(attribute_exists(#ndae5997d.#ncc96b5ad))",
ExpressionAttributeNames: {
"#n95d67ebc": "item",
"#n7e86b602": "parent",
"#ncc96b5ad": "item",
"#ndae5997d": "parent",
},
UpdateExpression: "REMOVE #n7e86b602.#n95d67ebc",
UpdateExpression: "REMOVE #ndae5997d.#ncc96b5ad",
};
expect(actual).toStrictEqual(expected);
});
Expand All @@ -99,12 +99,12 @@ describe("bug reports", () => {
const actual = dynoexpr(args);

const expected = {
ConditionExpression: "(attribute_exists(#n7e86b602.#n95d67ebc))",
ConditionExpression: "(attribute_exists(#ndae5997d.#ncc96b5ad))",
ExpressionAttributeNames: {
"#n95d67ebc": "item",
"#n7e86b602": "parent",
"#ncc96b5ad": "item",
"#ndae5997d": "parent",
},
UpdateExpression: "REMOVE #n7e86b602.#n95d67ebc",
UpdateExpression: "REMOVE #ndae5997d.#ncc96b5ad",
};
expect(actual).toStrictEqual(expected);
});
Expand All @@ -116,8 +116,8 @@ describe("bug reports", () => {
const actual = dynoexpr(args);

const expected = {
UpdateExpression: "SET #n596ceb9c = list_append(:v31e6eb45, #n596ceb9c)",
ExpressionAttributeNames: { "#n596ceb9c": "numbersArray" },
UpdateExpression: "SET #ne0c11d8d = list_append(:v31e6eb45, #ne0c11d8d)",
ExpressionAttributeNames: { "#ne0c11d8d": "numbersArray" },
ExpressionAttributeValues: { ":v31e6eb45": [1, 2] },
};
expect(actual).toStrictEqual(expected);
Expand All @@ -130,8 +130,8 @@ describe("bug reports", () => {
const actual = dynoexpr(args);

const expected = {
UpdateExpression: "SET #n596ceb9c = list_append(:v3578c5eb, #n596ceb9c)",
ExpressionAttributeNames: { "#n596ceb9c": "numbersArray" },
UpdateExpression: "SET #ne0c11d8d = list_append(:v3578c5eb, #ne0c11d8d)",
ExpressionAttributeNames: { "#ne0c11d8d": "numbersArray" },
ExpressionAttributeValues: { ":v3578c5eb": ["a", "b"] },
};
expect(actual).toStrictEqual(expected);
Expand Down

0 comments on commit 46d5aef

Please sign in to comment.