-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cd82eb4
commit 9d1a67d
Showing
1 changed file
with
69 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,77 @@ | ||
# Spacecat Shared - DynamoDB Client | ||
# Dynamo Client | ||
|
||
TBD | ||
## Overview | ||
This package, `@adobe/spacecat-shared-dynamo`, is a shared module designed for interacting with Amazon DynamoDB. It is a part of the Spacecat Services, providing a streamlined interface for DynamoDB operations. | ||
|
||
## Usage | ||
## Features | ||
- **Query Operations**: Perform read operations using primary or secondary indexes. | ||
- **Get Item**: Retrieve single items from DynamoDB using a table name and key. | ||
- **Put Item**: Insert or update items in DynamoDB. | ||
- **Remove Item**: Delete items from a DynamoDB table. | ||
|
||
## Installation | ||
Install the package using npm: | ||
``` | ||
npm install @adobe/spacecat-shared-dynamo | ||
``` | ||
|
||
```js | ||
## Usage | ||
First, import the `createClient` function from the package: | ||
```javascript | ||
import { createClient } from '@adobe/spacecat-shared-dynamo'; | ||
``` | ||
Then, use it to create a DynamoDB client: | ||
```javascript | ||
const dynamoClient = createClient(); | ||
``` | ||
|
||
### API Overview | ||
- `query(params)`: Queries DynamoDB with the specified parameters. | ||
- `getItem(tableName, key)`: Retrieves an item from a specified table using a key. | ||
- `putItem(tableName, item)`: Inserts or updates an item in the specified table. | ||
- `removeItem(tableName, key)`: Removes an item from the specified table. | ||
|
||
### Example | ||
```javascript | ||
const tableName = 'YourTableName'; | ||
const key = { primaryKey: 'YourPrimaryKey' }; | ||
|
||
// Get an item | ||
const item = await dynamoClient.getItem(tableName, key); | ||
|
||
// Put an item | ||
await dynamoClient.putItem(tableName, { primaryKey: 'NewKey', data: 'YourData' }); | ||
|
||
const dynamoDbClient = createClient(); | ||
// Query | ||
const queryResult = await dynamoClient.query({ TableName: tableName, KeyConditionExpression: 'primaryKey = :pk', ExpressionAttributeValues: { ':pk': 'YourPrimaryKey' } }); | ||
|
||
const result = await dynamoDbClient.query(...); | ||
... | ||
// Remove an item | ||
await dynamoClient.removeItem(tableName, key); | ||
``` | ||
|
||
## Testing | ||
Run the included tests with the following command: | ||
``` | ||
npm test | ||
``` | ||
|
||
## Linting | ||
Lint the codebase using: | ||
``` | ||
npm run lint | ||
``` | ||
|
||
## Cleaning | ||
To clean the package (remove `node_modules` and `package-lock.json`): | ||
``` | ||
npm run clean | ||
``` | ||
|
||
## Repository | ||
Find the source code and contribute [here](https://github.com/adobe-rnd/spacecat-shared.git). | ||
|
||
## Issues | ||
Report issues or bugs [here](https://github.com/adobe-rnd/spacecat-shared/issues). | ||
|
||
## License | ||
This project is licensed under the Apache-2.0 License. |