{"action":"created","issue":{"url":"https://api.github.com/repos/awslabs/dynamodb-data-mapper-js/issues/90","repository_url":"https://api.github.com/repos/awslabs/dynamodb-data-mapper-js","labels_url":"https://api.github.com/repos/awslabs/dynamodb-data-mapper-js/issues/90/labels{/name}","comments_url":"https://api.github.com/repos/awslabs/dynamodb-data-mapper-js/issues/90/comments","events_url":"https://api.github.com/repos/awslabs/dynamodb-data-mapper-js/issues/90/events","html_url":"https://github.com/awslabs/dynamodb-data-mapper-js/issues/90","id":345240198,"node_id":"MDU6SXNzdWUzNDUyNDAxOTg=","number":90,"title":"Can I ask for a better example in the expressions package?","user":{"login":"LucasBadico","id":16516889,"node_id":"MDQ6VXNlcjE2NTE2ODg5","avatar_url":"https://avatars3.githubusercontent.com/u/16516889?v=4","gravatar_id":"","url":"https://api.github.com/users/LucasBadico","html_url":"https://github.com/LucasBadico","followers_url":"https://api.github.com/users/LucasBadico/followers","following_url":"https://api.github.com/users/LucasBadico/following{/other_user}","gists_url":"https://api.github.com/users/LucasBadico/gists{/gist_id}","starred_url":"https://api.github.com/users/LucasBadico/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LucasBadico/subscriptions","organizations_url":"https://api.github.com/users/LucasBadico/orgs","repos_url":"https://api.github.com/users/LucasBadico/repos","events_url":"https://api.github.com/users/LucasBadico/events{/privacy}","received_events_url":"https://api.github.com/users/LucasBadico/received_events","type":"User","site_admin":false},"labels":[{"id":759423089,"node_id":"MDU6TGFiZWw3NTk0MjMwODk=","url":"https://api.github.com/repos/awslabs/dynamodb-data-mapper-js/labels/Documentation","name":"Documentation","color":"7a80dd","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-07-27T14:08:00Z","updated_at":"2018-09-23T15:10:50Z","closed_at":null,"author_association":"NONE","body":"I really have been strugly to undestand how to use it. For example, I need to make my dynamodb just make a update(acting as a create) if there is no `username`. I know that to doing that I have to do this:\r\n```js\r\ndynamodb.putItem({\r\n\t\t\tTableName: config.DDB_TABLE,\r\n\t\t\tItem: {\r\n\t\t\t\temail: {\r\n\t\t\t\t\tS: email\r\n\t\t\t\t},\r\n\t\t\t\tpasswordHash: {\r\n\t\t\t\t\tS: password\r\n\t\t\t\t},\r\n\t\t\t\tpasswordSalt: {\r\n\t\t\t\t\tS: salt\r\n\t\t\t\t},\r\n\t\t\t\tverified: {\r\n\t\t\t\t\tBOOL: false\r\n\t\t\t\t},\r\n\t\t\t\tverifyToken: {\r\n\t\t\t\t\tS: token\r\n\t\t\t\t}\r\n\t\t\t},\r\n\t\t\tConditionExpression: 'attribute_not_exists (email)'\r\n\t\t}, function(err, data) {\r\n\t\t\tif (err) return fn(err);\r\n\t\t\telse fn(null, token);\r\n\t\t});\r\n```\r\n\r\nHow I make this a operation with the ```mapper``` and ```expressions``` lib?"},"comment":{"url":"https://api.github.com/repos/awslabs/dynamodb-data-mapper-js/issues/comments/423823412","html_url":"https://github.com/awslabs/dynamodb-data-mapper-js/issues/90#issuecomment-423823412","issue_url":"https://api.github.com/repos/awslabs/dynamodb-data-mapper-js/issues/90","id":423823412,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMzgyMzQxMg==","user":{"login":"puzzloholic","id":7417938,"node_id":"MDQ6VXNlcjc0MTc5Mzg=","avatar_url":"https://avatars0.githubusercontent.com/u/7417938?v=4","gravatar_id":"","url":"https://api.github.com/users/puzzloholic","html_url":"https://github.com/puzzloholic","followers_url":"https://api.github.com/users/puzzloholic/followers","following_url":"https://api.github.com/users/puzzloholic/following{/other_user}","gists_url":"https://api.github.com/users/puzzloholic/gists{/gist_id}","starred_url":"https://api.github.com/users/puzzloholic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/puzzloholic/subscriptions","organizations_url":"https://api.github.com/users/puzzloholic/orgs","repos_url":"https://api.github.com/users/puzzloholic/repos","events_url":"https://api.github.com/users/puzzloholic/events{/privacy}","received_events_url":"https://api.github.com/users/puzzloholic/received_events","type":"User","site_admin":false},"created_at":"2018-09-23T15:10:50Z","updated_at":"2018-09-23T15:10:50Z","author_association":"NONE","body":"I have been playing with these library for a while, this is my proposed function using datamapper. I don't know whether `documents[0].documentNumber` will fail the function or not, as I never encounter such key before.\r\n```javascript\r\nimport { equals } from '@aws/dynamodb-expressions';\r\nexport async function getByCpf({ cpf, merchantId }) {\r\n    const keyCondition = {\r\n        merchantId: merchantId,\r\n    }\r\n    const predicate = equals(cpf);\r\n    const filterCondition = {\r\n        ...predicate,\r\n        subject: 'documents[0].documentNumber'\r\n    }\r\n    const queryOptions = {\r\n        filter: filterCondition\r\n    }\r\n    const iterator = mapper.query(myClass, keyCondition, queryOptions);\r\n    let result = [];\r\n    for await (const record of iterator) {\r\n        result.push(record);\r\n    }\r\n\r\n    return result;\r\n}\r\n```\r\n\r\n`queryOptions` will be translated as follows :\r\n```\r\nqueryOptions = {\r\n    filter:\r\n    {\r\n        type: 'Equals',\r\n        object: cpf,\r\n        subject: 'documents[0].documentNumber'\r\n    }\r\n}\r\n```\r\n\r\nYou can find full documentation about other expression here\r\nhttps://awslabs.github.io/dynamodb-data-mapper-js/packages/dynamodb-expressions/"}}
{"actor":{"display_login":"puzzloholic"}}