{"action":"created","issue":{"url":"https://api.github.com/repos/vitaly-t/pg-promise/issues/123","repository_url":"https://api.github.com/repos/vitaly-t/pg-promise","labels_url":"https://api.github.com/repos/vitaly-t/pg-promise/issues/123/labels{/name}","comments_url":"https://api.github.com/repos/vitaly-t/pg-promise/issues/123/comments","events_url":"https://api.github.com/repos/vitaly-t/pg-promise/issues/123/events","html_url":"https://github.com/vitaly-t/pg-promise/issues/123","id":150598119,"number":123,"title":"Convenience methods","user":{"login":"L-u-k-e","id":11082870,"avatar_url":"https://avatars.githubusercontent.com/u/11082870?v=3","gravatar_id":"","url":"https://api.github.com/users/L-u-k-e","html_url":"https://github.com/L-u-k-e","followers_url":"https://api.github.com/users/L-u-k-e/followers","following_url":"https://api.github.com/users/L-u-k-e/following{/other_user}","gists_url":"https://api.github.com/users/L-u-k-e/gists{/gist_id}","starred_url":"https://api.github.com/users/L-u-k-e/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/L-u-k-e/subscriptions","organizations_url":"https://api.github.com/users/L-u-k-e/orgs","repos_url":"https://api.github.com/users/L-u-k-e/repos","events_url":"https://api.github.com/users/L-u-k-e/events{/privacy}","received_events_url":"https://api.github.com/users/L-u-k-e/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/vitaly-t/pg-promise/labels/duplicate","name":"duplicate","color":"cccccc"},{"url":"https://api.github.com/repos/vitaly-t/pg-promise/labels/question","name":"question","color":"cc317c"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":17,"created_at":"2016-04-23T21:25:47Z","updated_at":"2016-05-12T15:12:53Z","closed_at":"2016-04-24T00:06:34Z","body":"Are there any convenience methods available that can infer the proper query syntax from the data containers themselves, rather than requiring a string?\r\n\r\nFor example, imagine a function like `db.insert_one(table_name, object)` for which the following invocation:\r\n   \r\n```\r\nvar my_video =  {id: ''CPgCDlOE09A', title: 'My Title', duration: 400.04, ... };\r\ndb.insert_one('video', my_video);\r\n```\r\n\r\nis equivalent to:\r\n\r\n```\r\ndb.one('insert into video (id, title, duration, ...) ' +\r\n'values ( $(id) $(title) $(duration) ... )', my_video);\r\n```\r\n\r\n\r\n\r\nThe function can infer the column name directly from the keys. As an example implementation consider the following (I'm using lodash here, but this is all directly translatable to vanilla): \r\n\r\n```\r\nvar create_insert_statement = function (table_name, obj) {\r\n\tvar keys = _.keys(obj);\r\n\tvar string = 'insert into ' + table_name + ' ' + \r\n\t\t'(' + keys.join(', ') + ') ' +\r\n\t\t'values (' + _.map(keys, function(s) { return '$('+s+')'}).join(', ') + ')';\r\n\treturn string;\t\r\n};\r\n```\r\n\r\nIf these functions don't exist, is there an interest in creating them/does anyone have any suggestions? (I'd be happy to contribute)\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/vitaly-t/pg-promise/issues/comments/218788546","html_url":"https://github.com/vitaly-t/pg-promise/issues/123#issuecomment-218788546","issue_url":"https://api.github.com/repos/vitaly-t/pg-promise/issues/123","id":218788546,"user":{"login":"vitaly-t","id":5108906,"avatar_url":"https://avatars.githubusercontent.com/u/5108906?v=3","gravatar_id":"","url":"https://api.github.com/users/vitaly-t","html_url":"https://github.com/vitaly-t","followers_url":"https://api.github.com/users/vitaly-t/followers","following_url":"https://api.github.com/users/vitaly-t/following{/other_user}","gists_url":"https://api.github.com/users/vitaly-t/gists{/gist_id}","starred_url":"https://api.github.com/users/vitaly-t/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vitaly-t/subscriptions","organizations_url":"https://api.github.com/users/vitaly-t/orgs","repos_url":"https://api.github.com/users/vitaly-t/repos","events_url":"https://api.github.com/users/vitaly-t/events{/privacy}","received_events_url":"https://api.github.com/users/vitaly-t/received_events","type":"User","site_admin":false},"created_at":"2016-05-12T15:12:53Z","updated_at":"2016-05-12T15:12:53Z","body":"@L-u-k-e I didn't get anymore feedback from you, and I have released the new feature as v.4.1.0.\r\n"}}