Difference between AWS SDK DynamoDB client and DocumentClient?(AWS SDK DynamoDB 客户端和 DocumentClient 之间的区别?)
问题描述
我想知道 AWS SDK DynamoDB 客户端和 DynamoDB DocumentClient 之间的区别?在哪个用例中我们应该使用 DynamoDB 客户端而不是 DocumentClient?
I want to know the difference between the AWS SDK DynamoDB client and the DynamoDB DocumentClient? In which use case should we use the DynamoDB client over the DocumentClient?
const dynamoClient = new AWS.DynamoDB.DocumentClient();
vs 
const dynamo = new AWS.DynamoDB();
推荐答案
我认为最好通过比较两个执行相同操作的代码示例来回答这个问题.
I think this can be best answered by comparing two code samples which do the same thing.
以下是使用 dynamoDB 客户端放置项目的方法:
Here's how you put an item using the dynamoDB client:
var params = {
    Item: {
        "AlbumTitle": {
            S: "Somewhat Famous"
        },
        "Artist": {
            S: "No One You Know"
        },
        "SongTitle": {
            S: "Call Me Today"
        }
    },
    TableName: "Music"
};
dynamodb.putItem(params, function (err, data) {
    if (err) console.log(err)
    else console.log(data);           
});
以下是使用 DocumentClient API 放置相同项目的方法:
Here's how you put the same item using the DocumentClient API:
var params = {
    Item: {
        "AlbumTitle": "Somewhat Famous",
        "Artist": "No One You Know",
        "SongTitle": "Call Me Today"
    },
    TableName: "Music"
};
var documentClient = new AWS.DynamoDB.DocumentClient();
documentClient.put(params, function (err, data) {
    if (err) console.log(err);
    else console.log(data);
});
正如您在 DocumentClient 中看到的那样,Item 以更自然的方式指定.更新 DDB 的所有其他操作(update()、delete())和从读取操作返回的项目(get()代码>,<代码>查询()代码>,<代码>扫描()代码>).
As you can see in the DocumentClient the Item is specified in a more natural way. Similar differences exist in all other operations that update DDB (update(), delete()) and in the items returned from read operations (get(), query(), scan()).
这篇关于AWS SDK DynamoDB 客户端和 DocumentClient 之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:AWS SDK DynamoDB 客户端和 DocumentClient 之间的区别?
 
				
         
 
            
        - 400或500级别的HTTP响应 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- Flexslider 箭头未正确显示 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- Fetch API 如何获取响应体? 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
 
						 
						 
						 
						 
						