标签:llb value mis OLE 映射 htm 没有 原创 青春
主题:
case ‘PUT‘: {
var table = ‘book_table‘, hash = ‘book‘, id = "05d101be-d5e8-43ec-8eb6-5530e21af83e";
var params = {
TableName: table,
Key: {
"hash": hash,
"id": id
},
UpdateExpression: "SET #p = :p, #sn = :n, #c = #c + :c",
ExpressionAttributeNames: {
"#p": "price",
"#sn": "sn",
"#c": "count"
},
ExpressionAttributeValues: {
":p": 100.99,
":n": "100-100-010",
":c": 1
},
ReturnValues: "UPDATED_NEW"
};
await docClient.update( params ).promise().then(
( success ) => {
response.body = JSON.stringify({ "success:": success })
}
).catch(
( err ) => {
console.log(err);
response.statusCode = err.statusCode;
response.body = JSON.stringify({
code: err.code,
message: err.message
})
}
);
callback( null, response );
break;
};
程序运行成功返回如下:
{
"success:": {
"Attributes": {
"count": 9,
"price": 100.99,
"sn": "100-100-010"
}
}
}
case ‘POST‘: {
var table = "book_table", hash = "book";
var params = {
TableName: table,
Item: {
"hash": hash,
"id": uuid(),
"booktype":[‘青春文学‘, ‘历史典故‘]
}
};
await docClient.put( params ).promise().then(
( data ) => {
response.body = JSON.stringify({"success": data})
}
).catch(
( err ) =>{
response = {
statusCode: err.statusCode,
body: JSON.stringify({
code: err.code,
message: err.message
})
}
}
)
callback( null, response );
break;
}
程序运行成功后返回:
{
"success": {}
}
case ‘PUT‘: {
var table = ‘book_table‘, hash = ‘book‘, id = "bee1bea0-4b6a-4fbc-8cf0-8c030519c909";
var params = {
TableName: table,
Key: {
"hash": hash,
"id": id
},
UpdateExpression: "SET #type = list_append(#type, :t)",
ExpressionAttributeNames: {
"#type": "booktype"
},
ExpressionAttributeValues: {
":t": ["读者杂志","最小说","科技畅想"]
},
};
await docClient.put( params ).promise().then(
( data ) => {
response.body = JSON.stringify({"success": data})
}
).catch(
( err ) =>{
response = {
statusCode: err.statusCode,
body: JSON.stringify({
code: err.code,
message: err.message
})
}
}
)
callback( null, response );
break;
}
程序运行成功后返回:
{
"success:": {
"Attributes": {
"booktype": [
"青春文学",
"历史典故",
"读者杂志",
"最小说",
"科技畅想",
],
"hash": "book",
"id": "556433cf-37b6-4e12-b513-9c261fd279f7"
}
}
}
case ‘POST‘: {
var table = "book_table", hash = "book";
var params = {
TableName: table,
Item: {
"hash": hash,
"id": uuid(),
"type": {
"list1": ["武侠小说", "社科图书"],
"list2": ["儿童读物", "漫画书"],
"list3": ["法律", "经济"]
}
}
};
await docClient.put( params ).promise().then(
( data ) => {
response.body = JSON.stringify({"success": data})
}
).catch(
( err ) =>{
response = {
statusCode: err.statusCode,
body: JSON.stringify({
code: err.code,
message: err.message
})
}
}
)
callback( null, response );
break;
}
case ‘PUT‘: {
var table = ‘book_table‘, hash = ‘book‘, id = "bee1bea0-4b6a-4fbc-8cf0-8c030519c909";
var params = {
TableName: table,
Key: {
"hash": hash,
"id": id
},
UpdateExpression: "SET #t.#l1 = :b1, #t.#l3 = :b3",
ExpressionAttributeNames: {
"#t": "type",
"#l1": "list1",
"#l3": "list3"
},
ExpressionAttributeValues: {
":b1": ["军事","艺术"],
":b3": ["社会","科学"]
},
ReturnValues: "ALL_NEW"
};
await docClient.update( params ).promise().then(
( success ) => {
response.body = JSON.stringify({ "success:": success })
}
).catch(
( err ) => {
console.log(err);
response.statusCode = err.statusCode;
response.body = JSON.stringify({
code: err.code,
message: err.message
})
}
);
callback( null, response );
break;
};
程序运行成功后返回:
{
"success:": {
"Attributes": {
"type": {
"list1": [
"军事",
"艺术"
],
"list3": [
"社会",
"科学"
],
"list2": [
"儿童读物",
"漫画书"
]
},
"hash": "book",
"id": "bee1bea0-4b6a-4fbc-8cf0-8c030519c909"
}
}
}
+(加号)和 -(减号)运算符。)case ‘POST‘: {
var table = "book_table", hash = "book";
var params = {
TableName: table,
Item: {
"hash": hash,
"id": uuid(),
"name": "三重门",
"author": "韩寒",
"type": "情感其他",
"sn": "100-100-008",
"price": 103.50,
"date": "2010-01-01",
"count": 7,
"description": "本书通过少年林雨翔的视角,向读者揭示了真实的高中生的生活,体现了学生式的思考、困惑和梦想。"
}
};
console.log( params.Item.count );
await docClient.put( params ).promise().then(
( data ) => {
response.body = JSON.stringify({"success": data})
}
).catch(
( err ) =>{
response = {
statusCode: err.statusCode,
body: JSON.stringify({
code: err.code,
message: err.message
})
}
}
)
callback( null, response );
break;
}
case ‘PUT‘: {
var table = ‘book_table‘, hash = ‘book‘, id = ‘4b99e00f-9f57-41f7-80de-d581e8c84522‘;
var params = {
TableName: table,
Key: {
"hash": hash,
"id": id
},
UpdateExpression: "SET #p = :p, #sn = :n, #c = #c + :c",
ExpressionAttributeNames: {
"#p": "price",
"#sn": "sn",
"#c": "count"
},
ExpressionAttributeValues: {
":p": 100.99,
":n": "100-100-010",
":c": 1
},
ReturnValues: "ALL_NEW"
};
await docClient.update( params ).promise().then(
( success ) => {
response.body = JSON.stringify({ "success:": success })
}
).catch(
( err ) => {
console.log(err);
response.statusCode = err.statusCode;
response.body = JSON.stringify({
code: err.code,
message: err.message
})
}
);
callback( null, response );
break;
};
程序运行成功后返回:
{
"success:": {
"Attributes": {
"date": "2010-01-01",
"author": "韩寒",
"price": 99.99,
"count": 8,
"name": "三重门",
"description": "本书通过少年林雨翔的视角,向读者揭示了真实的高中生的生活,体现了学生式的思考、困惑和梦想。",
"id": "4b99e00f-9f57-41f7-80de-d581e8c84522",
"sn": "100-100-100",
"type": "情感其他",
"hash": "book"
}
}
}
case ‘PUT‘: {
var table = ‘book_table‘, hash = ‘book‘, id = ‘4b99e00f-9f57-41f7-80de-d581e8c84522‘;
var params = {
TableName: table,
Key: {
"hash": hash,
"id": id
},
UpdateExpression: "SET #type = list_append(#type, :t)",
ExpressionAttributeNames: {
"#type": "booktype"
},
ExpressionAttributeValues: {
":t": ["穿越时空", "玄幻小说"]
},
ReturnValues: "ALL_NEW"
};
await docClient.update( params ).promise().then(
( success ) => {
response.body = JSON.stringify({ "success:": success })
}
).catch(
( err ) => {
console.log(err);
response.statusCode = err.statusCode;
response.body = JSON.stringify({
code: err.code,
message: err.message
})
}
);
callback( null, response );
break;
};
程序运行成功后返回:
{
"success:": {
"Attributes": {
"booktype": [
"青春文学",
"历史典故",
"读者杂志",
"最小说",
"科技畅想",
"穿越时空",
"玄幻小说"
],
"hash": "book",
"id": "556433cf-37b6-4e12-b513-9c261fd279f7"
}
}
}
case ‘PUT‘: {
var table = ‘book_table‘, hash = ‘book‘, id = ‘4b99e00f-9f57-41f7-80de-d581e8c84522‘;
var params = {
TableName: table,
Key: {
"hash": hash,
"id": id
},
UpdateExpression: "SET price = if_not_exists(price, :p)",
ExpressionAttributeValues: {
":p": 100
},
ReturnValues: "ALL_NEW"
};
await docClient.update( params ).promise().then(
( success ) => {
response.body = JSON.stringify({ "success:": success })
}
).catch(
( err ) => {
console.log(err);
response.statusCode = err.statusCode;
response.body = JSON.stringify({
code: err.code,
message: err.message
})
}
);
callback( null, response );
break;
};
程序运行成功后返回:
{
"success:": {
"Attributes": {
"booktype": [
"青春文学",
"历史典故",
"读者杂志",
"最小说",
"科技畅想",
"穿越时空",
"玄幻小说"
],
"id": "556433cf-37b6-4e12-b513-9c261fd279f7",
"price": 100,
"hash": "book"
}
}
}
case ‘PUT‘: {
var table = ‘book_table‘, hash = ‘book‘, id = ‘4b99e00f-9f57-41f7-80de-d581e8c84522‘;
var params = {
TableName: table,
Key: {
"hash": hash,
"id": id
},
UpdateExpression: "REMOVE booktype[6]",
ReturnValues: "ALL_NEW"
};
await docClient.update( params ).promise().then(
( success ) => {
response.body = JSON.stringify({ "success:": success })
}
).catch(
( err ) => {
console.log(err);
response.statusCode = err.statusCode;
response.body = JSON.stringify({
code: err.code,
message: err.message
})
}
);
callback( null, response );
break;
};
程序运行成功后返回:
{
"success:": {
"Attributes": {
"booktype": [
"青春文学",
"历史典故",
"读者杂志",
"最小说",
"科技畅想",
"穿越时空",
],
"id": "556433cf-37b6-4e12-b513-9c261fd279f7",
"price": 100,
"hash": "book"
}
}
}
注: ALL_NEW 将导致 DynamoDB 按更新后的情况返回项目;UPDATED_NEW仅将DynamoDB 按更新后的部分情况返回项目。
本文为原创,还望指教!
若有疑问,可在下方留言,也可自读AWS官方文档——DynamoDB: https://docs.aws.amazon.com/zh_cn/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html
标签:llb value mis OLE 映射 htm 没有 原创 青春
原文地址:https://www.cnblogs.com/landen/p/9780768.html