{"action":"created","comment":{"url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/pulls/comments/70917940","id":70917940,"diff_hunk":"@@ -624,6 +624,101 @@ DataAccessObject.upsert = function(data, options, cb) {\n   }\n   return cb.promise;\n };\n+/**\n+ * Performs upsert based on the instance that matches the where clause\n+ . This is a PUT operation and based on\n+ * non-primary key. The filter takes one key value pair and updates single matching instance.*\n+ */\n+DataAccessObject.upsertWithWhere = function(where, data, options, cb) {\n+  var connectionPromise = stillConnecting(this.getDataSource(), this, arguments);\n+  if (connectionPromise) {\n+    return connectionPromise;\n+  }\n+  assert(arguments.length >= 1, 'At least one argument is required');\n+  if (data === undefined && options === undefined && cb === undefined && arguments.length === 1) {\n+    data = where;\n+    where = {};\n+  } else if (options === undefined && cb === undefined) {\n+    if (typeof data === 'function') {\n+      cb = data;\n+      data = where;\n+      where = {};\n+    }\n+  } else if (cb === undefined) {\n+    if (typeof options === 'function') {\n+      cb = options;\n+      options = {};\n+    }\n+  }\n+  data = data || {};\n+  options = options || {};\n+  cb = cb || utils.createPromiseCallback();\n+  assert(typeof where === 'object', 'The where argument must be an object');\n+  assert(typeof data === 'object', 'The data argument must be an object');\n+  assert(typeof options === 'object', 'The options argument must be an object');\n+  assert(typeof cb === 'function', 'The cb argument must be a function');\n+  var hookState = {};\n+  var self = this;\n+  var Model = this;\n+  var connector = Model.getConnector();\n+  var modelObject = connector._models;\n+  var modelName = Object.keys(modelObject)[0];\n+  if (connector.upsertWithWhere) {\n+    return connector.upsertWithWhere(modelName, where, data, cb);\n+  } else {\n+    var element = Object.keys(where)[0];\n+    var filter = { 'where': where };\n+    if (Object.keys(data).length != 0) {\n+      if (!data.hasOwnProperty(element)) {\n+        data[element] = where[element];\n+      }\n+      var pk = idName(Model);\n+      self.find(filter, function(err, instances) {\n+        var modelsLength = instances.length;\n+        if (modelsLength === 0 && data.hasOwnProperty(pk)) {\n+          return self.create(data, options, cb);","path":"lib/dao.js","position":null,"original_position":56,"commit_id":"2de471869c9f538abaf7f2130d8aa536c866ea74","original_commit_id":"26d275178c92e94d0ae8d641fedea9a8ced91a57","user":{"login":"mountain1234585","id":18303722,"avatar_url":"https://avatars.githubusercontent.com/u/18303722?v=3","gravatar_id":"","url":"https://api.github.com/users/mountain1234585","html_url":"https://github.com/mountain1234585","followers_url":"https://api.github.com/users/mountain1234585/followers","following_url":"https://api.github.com/users/mountain1234585/following{/other_user}","gists_url":"https://api.github.com/users/mountain1234585/gists{/gist_id}","starred_url":"https://api.github.com/users/mountain1234585/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mountain1234585/subscriptions","organizations_url":"https://api.github.com/users/mountain1234585/orgs","repos_url":"https://api.github.com/users/mountain1234585/repos","events_url":"https://api.github.com/users/mountain1234585/events{/privacy}","received_events_url":"https://api.github.com/users/mountain1234585/received_events","type":"User","site_admin":false},"body":"Done!","created_at":"2016-07-15T03:42:21Z","updated_at":"2016-07-15T03:42:21Z","html_url":"https://github.com/strongloop/loopback-datasource-juggler/pull/1001#discussion_r70917940","pull_request_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/pulls/1001","_links":{"self":{"href":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/pulls/comments/70917940"},"html":{"href":"https://github.com/strongloop/loopback-datasource-juggler/pull/1001#discussion_r70917940"},"pull_request":{"href":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/pulls/1001"}}},"pull_request":{"url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/pulls/1001","id":77335191,"html_url":"https://github.com/strongloop/loopback-datasource-juggler/pull/1001","diff_url":"https://github.com/strongloop/loopback-datasource-juggler/pull/1001.diff","patch_url":"https://github.com/strongloop/loopback-datasource-juggler/pull/1001.patch","issue_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/1001","number":1001,"state":"open","locked":false,"title":"upsertWithWhere method","user":{"login":"mountain1234585","id":18303722,"avatar_url":"https://avatars.githubusercontent.com/u/18303722?v=3","gravatar_id":"","url":"https://api.github.com/users/mountain1234585","html_url":"https://github.com/mountain1234585","followers_url":"https://api.github.com/users/mountain1234585/followers","following_url":"https://api.github.com/users/mountain1234585/following{/other_user}","gists_url":"https://api.github.com/users/mountain1234585/gists{/gist_id}","starred_url":"https://api.github.com/users/mountain1234585/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mountain1234585/subscriptions","organizations_url":"https://api.github.com/users/mountain1234585/orgs","repos_url":"https://api.github.com/users/mountain1234585/repos","events_url":"https://api.github.com/users/mountain1234585/events{/privacy}","received_events_url":"https://api.github.com/users/mountain1234585/received_events","type":"User","site_admin":false},"body":"Added a new method for performing upsertWithWhere in dao.js","created_at":"2016-07-13T18:09:55Z","updated_at":"2016-07-15T03:42:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0e79394feea8367f67bca996026a8f1252ca80cc","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/pulls/1001/commits","review_comments_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/pulls/1001/comments","review_comment_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/pulls/comments{/number}","comments_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/1001/comments","statuses_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/statuses/2de471869c9f538abaf7f2130d8aa536c866ea74","head":{"label":"mountain1234585:upsertNPK","ref":"upsertNPK","sha":"2de471869c9f538abaf7f2130d8aa536c866ea74","user":{"login":"mountain1234585","id":18303722,"avatar_url":"https://avatars.githubusercontent.com/u/18303722?v=3","gravatar_id":"","url":"https://api.github.com/users/mountain1234585","html_url":"https://github.com/mountain1234585","followers_url":"https://api.github.com/users/mountain1234585/followers","following_url":"https://api.github.com/users/mountain1234585/following{/other_user}","gists_url":"https://api.github.com/users/mountain1234585/gists{/gist_id}","starred_url":"https://api.github.com/users/mountain1234585/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mountain1234585/subscriptions","organizations_url":"https://api.github.com/users/mountain1234585/orgs","repos_url":"https://api.github.com/users/mountain1234585/repos","events_url":"https://api.github.com/users/mountain1234585/events{/privacy}","received_events_url":"https://api.github.com/users/mountain1234585/received_events","type":"User","site_admin":false},"repo":{"id":63267897,"name":"loopback-datasource-juggler","full_name":"mountain1234585/loopback-datasource-juggler","owner":{"login":"mountain1234585","id":18303722,"avatar_url":"https://avatars.githubusercontent.com/u/18303722?v=3","gravatar_id":"","url":"https://api.github.com/users/mountain1234585","html_url":"https://github.com/mountain1234585","followers_url":"https://api.github.com/users/mountain1234585/followers","following_url":"https://api.github.com/users/mountain1234585/following{/other_user}","gists_url":"https://api.github.com/users/mountain1234585/gists{/gist_id}","starred_url":"https://api.github.com/users/mountain1234585/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mountain1234585/subscriptions","organizations_url":"https://api.github.com/users/mountain1234585/orgs","repos_url":"https://api.github.com/users/mountain1234585/repos","events_url":"https://api.github.com/users/mountain1234585/events{/privacy}","received_events_url":"https://api.github.com/users/mountain1234585/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mountain1234585/loopback-datasource-juggler","description":"Connect Loopback to various Data Sources","fork":true,"url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler","forks_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/forks","keys_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/teams","hooks_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/hooks","issue_events_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/issues/events{/number}","events_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/events","assignees_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/assignees{/user}","branches_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/branches{/branch}","tags_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/tags","blobs_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/git/refs{/sha}","trees_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/statuses/{sha}","languages_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/languages","stargazers_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/stargazers","contributors_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/contributors","subscribers_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/subscribers","subscription_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/subscription","commits_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/commits{/sha}","git_commits_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/git/commits{/sha}","comments_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/comments{/number}","issue_comment_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/issues/comments{/number}","contents_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/contents/{+path}","compare_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/merges","archive_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/downloads","issues_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/issues{/number}","pulls_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/pulls{/number}","milestones_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/milestones{/number}","notifications_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/labels{/name}","releases_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/releases{/id}","deployments_url":"https://api.github.com/repos/mountain1234585/loopback-datasource-juggler/deployments","created_at":"2016-07-13T17:55:56Z","updated_at":"2016-07-13T17:55:58Z","pushed_at":"2016-07-15T03:25:11Z","git_url":"git://github.com/mountain1234585/loopback-datasource-juggler.git","ssh_url":"git@github.com:mountain1234585/loopback-datasource-juggler.git","clone_url":"https://github.com/mountain1234585/loopback-datasource-juggler.git","svn_url":"https://github.com/mountain1234585/loopback-datasource-juggler","homepage":"http://www.loopback.io","size":5704,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"strongloop:master","ref":"master","sha":"cca14a0230e51cb47795742f903e0eec7f35d7dd","user":{"login":"strongloop","id":3020012,"avatar_url":"https://avatars.githubusercontent.com/u/3020012?v=3","gravatar_id":"","url":"https://api.github.com/users/strongloop","html_url":"https://github.com/strongloop","followers_url":"https://api.github.com/users/strongloop/followers","following_url":"https://api.github.com/users/strongloop/following{/other_user}","gists_url":"https://api.github.com/users/strongloop/gists{/gist_id}","starred_url":"https://api.github.com/users/strongloop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/strongloop/subscriptions","organizations_url":"https://api.github.com/users/strongloop/orgs","repos_url":"https://api.github.com/users/strongloop/repos","events_url":"https://api.github.com/users/strongloop/events{/privacy}","received_events_url":"https://api.github.com/users/strongloop/received_events","type":"Organization","site_admin":false},"repo":{"id":10126908,"name":"loopback-datasource-juggler","full_name":"strongloop/loopback-datasource-juggler","owner":{"login":"strongloop","id":3020012,"avatar_url":"https://avatars.githubusercontent.com/u/3020012?v=3","gravatar_id":"","url":"https://api.github.com/users/strongloop","html_url":"https://github.com/strongloop","followers_url":"https://api.github.com/users/strongloop/followers","following_url":"https://api.github.com/users/strongloop/following{/other_user}","gists_url":"https://api.github.com/users/strongloop/gists{/gist_id}","starred_url":"https://api.github.com/users/strongloop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/strongloop/subscriptions","organizations_url":"https://api.github.com/users/strongloop/orgs","repos_url":"https://api.github.com/users/strongloop/repos","events_url":"https://api.github.com/users/strongloop/events{/privacy}","received_events_url":"https://api.github.com/users/strongloop/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/strongloop/loopback-datasource-juggler","description":"Connect Loopback to various Data Sources","fork":false,"url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler","forks_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/forks","keys_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/keys{/key_id}","collaborators_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/teams","hooks_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/hooks","issue_events_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/events{/number}","events_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/events","assignees_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/assignees{/user}","branches_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/branches{/branch}","tags_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/tags","blobs_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/git/refs{/sha}","trees_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/git/trees{/sha}","statuses_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/statuses/{sha}","languages_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/languages","stargazers_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/stargazers","contributors_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/contributors","subscribers_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/subscribers","subscription_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/subscription","commits_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/commits{/sha}","git_commits_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/git/commits{/sha}","comments_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/comments{/number}","issue_comment_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/comments{/number}","contents_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/contents/{+path}","compare_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/compare/{base}...{head}","merges_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/merges","archive_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/downloads","issues_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues{/number}","pulls_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/pulls{/number}","milestones_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/milestones{/number}","notifications_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/labels{/name}","releases_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/releases{/id}","deployments_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/deployments","created_at":"2013-05-17T15:56:04Z","updated_at":"2016-06-28T18:45:59Z","pushed_at":"2016-07-15T03:06:55Z","git_url":"git://github.com/strongloop/loopback-datasource-juggler.git","ssh_url":"git@github.com:strongloop/loopback-datasource-juggler.git","clone_url":"https://github.com/strongloop/loopback-datasource-juggler.git","svn_url":"https://github.com/strongloop/loopback-datasource-juggler","homepage":"http://www.loopback.io","size":6212,"stargazers_count":138,"watchers_count":138,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":194,"mirror_url":null,"open_issues_count":208,"forks":194,"open_issues":208,"watchers":138,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/pulls/1001"},"html":{"href":"https://github.com/strongloop/loopback-datasource-juggler/pull/1001"},"issue":{"href":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/1001"},"comments":{"href":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/1001/comments"},"review_comments":{"href":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/pulls/1001/comments"},"review_comment":{"href":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/pulls/1001/commits"},"statuses":{"href":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/statuses/2de471869c9f538abaf7f2130d8aa536c866ea74"}}}}
{"actor":{"display_login":"mountain1234585"}}