@moicky/dynamodb 1.2.2 → 1.2.3

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 +11 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moicky/dynamodb",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
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
@@ -146,8 +146,7 @@ await deleteItem({
146
146
  });
147
147
 
148
148
  // Delete multiple items
149
- // KeySchemas will be grouped into batches of 25 and will be retried up to 3 times if there are unprocessed items
150
- // Will only delete each keySchema only once, even if it is present multiple times in the array to improve performance
149
+ // Will only delete each keySchema once, even if it is present multiple times in the array to improve performance and avoid aws errors
151
150
  await deleteItems([
152
151
  { PK: "User/1", SK: "Book/1" },
153
152
  // ... infinite more items (will be grouped into batches of 25 due to aws limit) and retried up to 3 times
@@ -161,13 +160,13 @@ import { updateItem, removeAttributes } from "@moicky/dynamodb";
161
160
 
162
161
  // Update the item and overwrite all supplied fields
163
162
  await updateItem(
164
- { PK: "User/1", SK: "Book/1" },
165
- { description: "A book about a rich guy", author: "F. Scott Fitzgerald" }
163
+ { PK: "User/1", SK: "Book/1" }, // reference to item
164
+ { description: "A book about a rich guy", author: "F. Scott Fitzgerald" } // fields to update
166
165
  );
167
166
 
168
167
  await updateItem(
169
168
  { PK: "User/1", SK: "Book/1" },
170
- { released: 2000, maxReleased: 1950 }, // maxReleased will not be updated, since it is referenced inside the ConditionExpression
169
+ { released: 2000, maxReleased: 1950 }, // maxReleased will not be updated on the item, since it is referenced inside the ConditionExpression
171
170
  { ConditionExpression: "#released < :maxReleased" }
172
171
  );
173
172
 
@@ -187,7 +186,7 @@ await removeAttributes({ PK: "User/1", SK: "Book/1" }, ["description"]);
187
186
  import { query, queryItems, queryAllItems } from "@moicky/dynamodb";
188
187
 
189
188
  // You HAVE TO use placeholders for the keyCondition & filterExpression:
190
- // prefix the attributeNames with a hash (#) and the attributeValues with a colon (:)
189
+ // Prefix the attributeNames with a hash (#) and the attributeValues with a colon (:)
191
190
 
192
191
  // Query only using keyCondition and retrieve complete response
193
192
  const booksResponse = await query("#PK = :PK and begins_with(#SK, :SK)", {
@@ -217,8 +216,8 @@ const booksWithFilter = await queryAllItems(
217
216
  from: 1950,
218
217
  to: 2000,
219
218
  },
220
- // additional args with filterExpression
221
- { FilterExpression: "#released BETWEEN :from AND :to" } // allows to override all args
219
+ // additional args with filterExpression for example
220
+ { FilterExpression: "#released BETWEEN :from AND :to" }
222
221
  );
223
222
  ```
224
223
 
@@ -229,6 +228,7 @@ import { itemExists, getAscendingId } from "@moicky/dynamodb";
229
228
 
230
229
  // Check if an item exists using keySchema
231
230
  const exists = await itemExists({ PK: "User/1", SK: "Book/1" });
231
+ console.log(exists); // true / false
232
232
 
233
233
  // Generate ascending ID
234
234
  // Specify keySchemaHash and optionally item to start at using keySchemaRange
@@ -240,18 +240,18 @@ console.log(id1); // "00000010"
240
240
 
241
241
  // Example Structure 2: PK: "User/1", SK: "Book/{{ ASCENDING_ID }}"
242
242
  // Last item: { PK: "User/1", SK: "Book/00000009" }
243
- const id2 = await getAscendingId({ PK: "User/1", SKPrefix: "Book" });
243
+ const id2 = await getAscendingId({ PK: "User/1", SK: "Book" });
244
244
  console.log(id2); // "00000010"
245
245
 
246
246
  // Specify length of ID
247
- const id3 = await getAscendingId({ PK: "User/1", SKPrefix: "Book", length: 4 });
247
+ const id3 = await getAscendingId({ PK: "User/1", SK: "Book", length: 4 });
248
248
  console.log(id3); // "0010"
249
249
 
250
250
  // Example Structure 3: someKeySchemaHash: "User/1", SK: "Book/{{ ASCENDING_ID }}"
251
251
  // Last item: { someKeySchemaHash: "User/1", SK: "Book/00000009" }
252
252
  const id4 = await getAscendingId({
253
253
  someKeySchemaHash: "User/1",
254
- SKPrefix: "Book",
254
+ SK: "Book",
255
255
  });
256
256
  console.log(id4); // "00000010"
257
257
  ```