• DynamoDB-过滤表达式


    • contains (path, operand)
    case 'GET': {
    
                var next = null;
                if( event.queryStringParameters && event.queryStringParameters.next ){
                    next = JSON.parse( event.queryStringParameters.next );
                }
                console.log( next );
    
                var params = {
                    TableName: "book_table",
                    KeyConditionExpression: "#key = :value",
                    //contains(path, operand)
                     FilterExpression: "contains(#n, :n) and #p < :p",
                    ExpressionAttributeNames: {
                        "#key": "hash",
                        "#n": "name",
                        "#p": "price"
                    },
                    ExpressionAttributeValues: {
                        ":p": 188.88,
                        ":n": "三重门",
                        ":value": "book"
                    },
                    Limit: 10
                };
    
                if( next ){
                    params = {...params, ExclusiveStartKey: next.LastEvaluatedKey };
                }
            
                await docClient.query( params ).promise().then(
                    ( data ) => {
                        response.body = JSON.stringify({ "success": data });
                        callback( null, response );
                    }
                ).catch(
                    ( err ) => {
                        response.statusCode = err.statusCode;
                            response.body = JSON.stringify({
                                code: err.code,
                                message: err.message
                            });
                            callback( null, response );
                    }
                )
                break;
            }

    程序运行成功后返回:

     1 {
     2     "success": {
     3         "Items": [
     4             {
     5                 "date": "2010-01-01",
     6                 "author": "韩寒",
     7                 "price": 55.55,
     8                 "zan": 520,
     9                 "count": 10,
    10                 "name": "三重门",
    11                 "description": "本书通过少年林雨翔的视角,向读者揭示了真实的高中生的生活,体现了学生式的思考、困惑和梦想。",
    12                 "id": "05d101be-d5e8-43ec-8eb6-5530e21af83e",
    13                 "sn": "100-100-010",
    14                 "type": "情感其他",
    15                 "uri": "https://www.cnblogs.com/landen/p/9790704.html ",
    16                 "hash": "book"
    17             },
    18             {
    19                 "date": "2010-01-01",
    20                 "author": "韩寒",
    21                 "price": 99.99,
    22                 "count": 8,
    23                 "name": "三重门",
    24                 "description": "本书通过少年林雨翔的视角,向读者揭示了真实的高中生的生活,体现了学生式的思考、困惑和梦想。",
    25                 "id": "4b99e00f-9f57-41f7-80de-d581e8c84522",
    26                 "sn": "100-100-100",
    27                 "type": "情感其他",
    28                 "hash": "book"
    29             },
    30             {
    31                 "date": "2010-01-01",
    32                 "author": "韩寒",
    33                 "price": 23.5,
    34                 "count": 7,
    35                 "name": "三重门",
    36                 "description": "本书通过少年林雨翔的视角,向读者揭示了真实的高中生的生活,体现了学生式的思考、困惑和梦想。",
    37                 "id": "5ed6bce8-3ffb-46c8-bc04-04b31d922fd8",
    38                 "sn": "100-100-008",
    39                 "type": "情感其他",
    40                 "hash": "book"
    41             },
    42             {
    43                 "date": "2010-01-01",
    44                 "author": "韩寒",
    45                 "price": 23.5,
    46                 "name": "三重门",
    47                 "count": 7,
    48                 "description": "本书通过少年林雨翔的视角,向读者揭示了真实的高中生的生活,体现了学生式的思考、困惑和梦想。",
    49                 "id": "6f1e4501-f2ba-499f-a2ad-d1173adc062a",
    50                 "sn": "100-100-008",
    51                 "type": "情感其他",
    52                 "hash": "book"
    53             },
    54             {
    55                 "date": "2010-01-01",
    56                 "author": "韩寒",
    57                 "price": 23.5,
    58                 "name": "三重门",
    59                 "description": "本书通过少年林雨翔的视角,向读者揭示了真实的高中生的生活,体现了学生式的思考、困惑和梦想。",
    60                 "id": "898a4f74-648d-4996-8ff9-3395c668d506",
    61                 "sn": "100-100-008",
    62                 "type": "情感其他",
    63                 "hash": "book"
    64             },
    65             {
    66                 "date": "2010-01-01",
    67                 "author": "韩寒",
    68                 "price": 103.5,
    69                 "name": "三重门",
    70                 "count": 7,
    71                 "description": "本书通过少年林雨翔的视角,向读者揭示了真实的高中生的生活,体现了学生式的思考、困惑和梦想。",
    72                 "id": "8baff9a7-179b-46b3-801d-5e7b9abd3dfe",
    73                 "sn": "100-100-008",
    74                 "type": "情感其他",
    75                 "hash": "book"
    76             },
    77             {
    78                 "date": "2010-01-01",
    79                 "author": "韩寒",
    80                 "price": 103.5,
    81                 "name": "三重门",
    82                 "count": 7,
    83                 "description": "本书通过少年林雨翔的视角,向读者揭示了真实的高中生的生活,体现了学生式的思考、困惑和梦想。",
    84                 "id": "960eb7c2-5ac1-4e9a-859e-31c2c8754972",
    85                 "sn": "100-100-008",
    86                 "type": "情感其他",
    87                 "hash": "book"
    88             }
    89         ],
    90         "Count": 7,
    91         "ScannedCount": 10,
    92         "LastEvaluatedKey": {
    93             "hash": "book",
    94             "id": "9787540475581"
    95         }
    96     }
    97 }
    View Code

    本文为原创,还望指教!

    若有疑问,可在下方留言,也可自读AWS官方文档——DynamoDB:https://docs.aws.amazon.com/zh_cn/amazondynamodb/latest/developerguide/Expressions.ExpressionAttributeValues.html

  • 相关阅读:
    棋盘问题 POJ
    Fire! UVA
    走迷宫(bfs, 最短路)
    ASP-Command-SQL格式
    ASP连接数据库SQLServer
    Bootstrap学习-导航条-分页导航
    Bootstrap导航栏头部错位问题
    SQLServer判断一个IP是否在一个IP段里
    MySQL合并多行
    CSS图片居中,多余隐藏
  • 原文地址:https://www.cnblogs.com/landen/p/9797088.html
Copyright © 2020-2023  润新知