@moicky/dynamodb 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/readme.md +10 -34
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moicky/dynamodb",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "description": "Contains a collection of convenience functions for working with AWS DynamoDB",
package/readme.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # @moicky/dynamodb
2
2
 
3
- ## Stats
4
-
5
3
  ![](https://img.shields.io/github/languages/top/moicky/dynamodb)
6
4
  ![](https://img.shields.io/github/actions/workflow/status/moicky/dynamodb/npm-publish.yml?label=build)
7
5
  ![](https://img.shields.io/github/actions/workflow/status/moicky/dynamodb/run-tests.yml?label=tests)
@@ -14,6 +12,7 @@ Contains convenience functions for all major dynamodb operations. Requires very
14
12
 
15
13
  - 🎁 Will **automatically marshall and unmarshall** items
16
14
  - 📦 Will **group items into batches** to avoid aws limits and improve performance
15
+ - ⏱ Will **automatically** add `createdAt` and `updatedAt` attributes on all items to track their most recent create/update operation timestamp. Example value: `Date.now() -> 1685138436000`
17
16
  - 🔄 Will **retry** some operations (getItems, deleteItems) **up to 3 times** on unprocessed items
18
17
  - 🔒 When specifying an item using its keySchema, all additional attributes (apart from **PK** and **SK**) will be removed to avoid errors
19
18
  - 👻 Will **use placeholders** to avoid colliding with [reserved words](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ReservedWords.html) if applicable
@@ -98,28 +97,20 @@ await getAllItems();
98
97
  ```ts
99
98
  import { deleteItem, deleteItems } from "@moicky/dynamodb";
100
99
 
101
- // Passing more than just the key is possible, but will be removed to avoid errors
102
-
103
100
  // Delete single item
104
101
  await deleteItem({
105
102
  PK: "User/1",
106
103
  SK: "Book/1",
107
- title: "The Great Gatsby", // additional fields will be removed before sending
104
+ title: "The Great Gatsby", // additional fields will be removed before sending to avoid errors
108
105
  author: "F. Scott Fitzgerald",
109
106
  released: 1925,
110
107
  });
111
108
 
112
109
  // Delete multiple items
113
- // Keys will be grouped into batches of 25 and will be retried up to 3 times if there are unprocessed items
114
- // Will also only delete each keySchema once, even if it is present multiple times in the array to improve performance
110
+ // KeySchemas will be grouped into batches of 25 and will be retried up to 3 times if there are unprocessed items
111
+ // Will only delete each keySchema only once, even if it is present multiple times in the array to improve performance
115
112
  await deleteItems([
116
- {
117
- PK: "User/1",
118
- SK: "Book/1",
119
- title: "The Great Gatsby", // additional fields will be removed before sending
120
- author: "F. Scott Fitzgerald",
121
- released: 1925,
122
- },
113
+ { PK: "User/1", SK: "Book/1" },
123
114
  // ... infinite more items (will be grouped into batches of 25 due to aws limit) and retried up to 3 times
124
115
  ]);
125
116
  ```
@@ -129,27 +120,13 @@ await deleteItems([
129
120
  ```ts
130
121
  import { updateItem, removeAttributes } from "@moicky/dynamodb";
131
122
 
132
- // Passing more than just the key is possible, but will be removed to avoid errors
133
-
134
123
  // Update the item and overwrite all supplied fields
135
124
  await updateItem(
136
- {
137
- PK: "User/1",
138
- SK: "Book/1",
139
- title: "The Great Gatsby", // additional fields will be removed before sending
140
- },
125
+ { PK: "User/1", SK: "Book/1" },
141
126
  { description: "A book about a rich guy", author: "F. Scott Fitzgerald" }
142
127
  );
143
128
 
144
- // Completely remove fields from the item
145
- await removeAttributes(
146
- {
147
- PK: "User/1",
148
- SK: "Book/1",
149
- title: "The Great Gatsby", // additional fields will be removed before sending
150
- },
151
- ["description"]
152
- );
129
+ await removeAttributes({ PK: "User/1", SK: "Book/1" }, ["description"]);
153
130
  ```
154
131
 
155
132
  ### Query Items
@@ -157,7 +134,7 @@ await removeAttributes(
157
134
  ```ts
158
135
  import { query, queryItems, queryAllItems } from "@moicky/dynamodb";
159
136
 
160
- // You have to use placeholders for the keyCondition & filterExpression:
137
+ // You HAVE TO use placeholders for the keyCondition & filterExpression:
161
138
  // prefix the attributeNames with a hash (#) and the attributeValues with a colon (:)
162
139
 
163
140
  // Query only using keyCondition and retrieve complete response
@@ -189,7 +166,7 @@ const booksWithFilter = await queryAllItems(
189
166
  to: 2000,
190
167
  },
191
168
  // additional args with filterExpression
192
- { FilterExpression: "#released BETWEEN :from AND :to" }
169
+ { FilterExpression: "#released BETWEEN :from AND :to" } // allows to override all args
193
170
  );
194
171
  ```
195
172
 
@@ -202,15 +179,14 @@ import { itemExists, getNewId } from "@moicky/dynamodb";
202
179
  const exists = await itemExists({ PK: "User/1", SK: "Book/1" });
203
180
 
204
181
  // Generate ascending ID
182
+
205
183
  // Example Structure 1: PK: "User/1", SK: "{{ ASCENDING_ID }}"
206
184
  // Last item: { PK: "User/1", SK: "00000009" }
207
-
208
185
  const id1 = await getNewId({ PK: "User/1" });
209
186
  console.log(id1); // "00000010"
210
187
 
211
188
  // Example Structure 2: PK: "User/1", SK: "Book/{{ ASCENDING_ID }}"
212
189
  // Last item: { PK: "User/1", SK: "Book/00000009" }
213
-
214
190
  const id2 = await getNewId({ PK: "User/1", SK: "Book" });
215
191
  console.log(id2); // "00000010"
216
192