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

Question: access to raw ddb documentClient? #681

Open
ktwbc opened this issue Apr 27, 2024 · 1 comment
Open

Question: access to raw ddb documentClient? #681

ktwbc opened this issue Apr 27, 2024 · 1 comment

Comments

@ktwbc
Copy link

ktwbc commented Apr 27, 2024

I had some code using dynamo-types where I was just grabbing the connection made by that library and doing a direct sdk call, and I had access to it with this command:

const ddbClient = MyTableClass.metadata.connection.documentClient;
await dynamoDb.update({
                TableName: MyTableClass.metadata.name,
                Key: { id: 123},
                UpdateExpression: 'remove #c',
                ExpressionAttributeNames: {
                  '#c': 'current_employees'
                }
              })
              .promise();

I see in the docs/code that Dyngoose has a DocumentClient which can be defined in the model but this looks like something different, a coincidentally named class and not the actual @AWS-SDK documentClient. I did find in the source code something like

MyTableClass.schema.dynamodb but this isn't the client either, although MyTableClass.schema.name looks like it would be the table name that's usable. Any advice on how to make "direct" sdk code work with the ORM (which I know long term just convert into ORM code but that's a refactor for later, right now just doing a transition.)

@benhutchins
Copy link
Owner

Sorry for a late response here. I am not sure if you've found a workaround to this, if so, please let me know how you worked around this.

DynamoDB doesn't rely on the aws-sdk DocumentClient, it has its own wrapper for transforming values bidirectionally between DynamoDB and JavaScript, which internally can fallback to the same marshall utility that aws-sdk uses.

There is a confusingly similarly class named the DocumentClient though. It's exposed as a way to get the operation Dynoose will call when calling put, update, or delete to either review the operations or manipulate them and pass them directly to a DynamoDB Client.

Dyngoose exposes some utilities like update on the PrimaryKey class, but the APIs are not the same.

You can create an aws-sdk DocumentClient and keep the same calls, if you'd like to reuse the same dynamodb connection, Dyngoose does expose that on the tables as MyTableClass.schema.dynamo which can be used to create a DocumentClient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants