Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add aws-dynamodb driver #234

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft

Conversation

daaru00
Copy link

@daaru00 daaru00 commented May 25, 2023

Add support for Amazon DynamoDB.
Also add support for DynamoDB Time to Live (TTL), this is order to manage key expiration.

A note about "aws-dynamodb" driver's tests: they will fail if no valid AWS credentials will be found (using profile or environment variables).

@nuxt-studio
Copy link

nuxt-studio bot commented May 25, 2023

Live Preview ready!

Name Edit Preview Latest Commit
unstorage Edit on Studio ↗︎ View Live Preview b100537

@Hebilicious Hebilicious added enhancement New feature or request driver labels Jun 30, 2023 — with Volta.net
@Hebilicious Hebilicious self-assigned this Jun 30, 2023
@Hebilicious Hebilicious self-requested a review June 30, 2023 17:23
@Hebilicious Hebilicious removed the enhancement New feature or request label Jun 30, 2023 — with Volta.net
@pi0 pi0 changed the title feat(drivers): add support for AWS DynamoDB feat(drivers): add support for aws dynamodb Aug 7, 2023
@pi0 pi0 marked this pull request as draft August 7, 2023 20:18
@pi0
Copy link
Member

pi0 commented Aug 7, 2023

Thanks for the PR @daaru00. Checking locally, the types and test are failing. Can you please check? 🙏🏼

@daaru00
Copy link
Author

daaru00 commented Aug 9, 2023

Hello @pi0,

May I ask what error message you get?
I suspect it's something related to AWS credentials, without them the integration tests will fail not being able to access a valid AWS account (in order to create a temporary table to run tests on).

@pi0
Copy link
Member

pi0 commented Aug 9, 2023

I suspect it's something related to AWS credentials, without them the integration tests will fail not being able to access a valid AWS account (in order to create a temporary table to run tests on).

Do you think we can mock AWS library to make sure tests run locally?

@daaru00
Copy link
Author

daaru00 commented Aug 28, 2023

@pi0 I did a test using the official mock library managed by AWS: https://aws.amazon.com/it/blogs/developer/mocking-modular-aws-sdk-for-javascript-v3-in-unit-tests/.
Actually I replaced the api calls using Map saving key and value in-memory:

client
    .on(GetCommand)
    .callsFake(input => {
      const key = input.Key.key
      if (!data.has(key)) {
        return { Item: undefined }
      }
      return { Item: { key, value: data.get(key) } }
    })
    .on(ScanCommand)
    .callsFake(() => {
      return { Items: Array.from(data.entries()).map(([ key, value ]) => ({ key, value })) }
    })
    .on(PutCommand)
    .callsFake(input => {
      data.set(input.Item.key, input.Item.value)
    })
    .on(DeleteCommand)
    .callsFake(input => {
      data.delete(input.Key.key)
    })

Is this the expected result?

ps: I also had to update the AWS SDK due to some internal conflicts with typescript types

ttl?: string;
};
expireIn?: number;
client?: DynamoDBDocumentClient;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to have ttl as a top level option here, for consistency with other drivers #262

async getItem(key) {
return await getItemValue(key);
},
async setItem(key, value) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could accept, key, value, options with { ttl } in options for per object expiration.

@aheissenberger
Copy link

what is the timeline for this to be merged into master?

@pi0 pi0 changed the title feat(drivers): add support for aws dynamodb feat(drivers): add aws-dynamodb driver May 1, 2024
@pi0 pi0 changed the title feat(drivers): add aws-dynamodb driver feat: add aws-dynamodb driver May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants