{"action":"created","issue":{"url":"https://api.github.com/repos/tgriesser/knex/issues/1633","repository_url":"https://api.github.com/repos/tgriesser/knex","labels_url":"https://api.github.com/repos/tgriesser/knex/issues/1633/labels{/name}","comments_url":"https://api.github.com/repos/tgriesser/knex/issues/1633/comments","events_url":"https://api.github.com/repos/tgriesser/knex/issues/1633/events","html_url":"https://github.com/tgriesser/knex/issues/1633","id":171841318,"node_id":"MDU6SXNzdWUxNzE4NDEzMTg=","number":1633,"title":"Support for ON CONFLICT clause for INSERTs","user":{"login":"qcom","id":706027,"node_id":"MDQ6VXNlcjcwNjAyNw==","avatar_url":"https://avatars2.githubusercontent.com/u/706027?v=4","gravatar_id":"","url":"https://api.github.com/users/qcom","html_url":"https://github.com/qcom","followers_url":"https://api.github.com/users/qcom/followers","following_url":"https://api.github.com/users/qcom/following{/other_user}","gists_url":"https://api.github.com/users/qcom/gists{/gist_id}","starred_url":"https://api.github.com/users/qcom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qcom/subscriptions","organizations_url":"https://api.github.com/users/qcom/orgs","repos_url":"https://api.github.com/users/qcom/repos","events_url":"https://api.github.com/users/qcom/events{/privacy}","received_events_url":"https://api.github.com/users/qcom/received_events","type":"User","site_admin":false},"labels":[{"id":23356640,"node_id":"MDU6TGFiZWwyMzM1NjY0MA==","url":"https://api.github.com/repos/tgriesser/knex/labels/feature%20request","name":"feature request","color":"84b6eb","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-08-18T08:06:44Z","updated_at":"2018-09-15T19:07:15Z","closed_at":null,"author_association":"NONE","body":"For now I achieved this by constructing a set of parenthesized  `VALUES` terms and calling `knex.raw()` with the built string and array of params:\n\n``` javascript\nfunction insertRecordsOnConflictDoNothing(table, records) {\n  const keys = Object.keys(records[0]);\n\n  const getIdentifierSpots = () => keys.map(() => '??').join(', ');\n  const getValueSpots = () => keys.map(() => '?').join(', ');\n\n  const columns = `(${getIdentifierSpots()})`;\n  const values = records.map(() => `(${getValueSpots()})`).join(', ');\n\n  const valueArgs = records\n    .map(record => keys.map(key => record[key]))\n    .reduce((array, record) => [...array, ...record], []);\n\n  const rawString = `${columns} VALUES ${values} ON CONFLICT DO NOTHING`;\n  const args = [...keys, ...valueArgs];\n\n  return knex(table)\n    .insert(knex.raw(rawString, args));\n}\n```\n\nObviously this is suboptimal but I'm not too familiar with the knex api. Is there a better method to get this behavior currently?\n\nIf this is a desired feature, let me know if I can help implement.\n"},"comment":{"url":"https://api.github.com/repos/tgriesser/knex/issues/comments/421618400","html_url":"https://github.com/tgriesser/knex/issues/1633#issuecomment-421618400","issue_url":"https://api.github.com/repos/tgriesser/knex/issues/1633","id":421618400,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMTYxODQwMA==","user":{"login":"Industrial","id":3317,"node_id":"MDQ6VXNlcjMzMTc=","avatar_url":"https://avatars2.githubusercontent.com/u/3317?v=4","gravatar_id":"","url":"https://api.github.com/users/Industrial","html_url":"https://github.com/Industrial","followers_url":"https://api.github.com/users/Industrial/followers","following_url":"https://api.github.com/users/Industrial/following{/other_user}","gists_url":"https://api.github.com/users/Industrial/gists{/gist_id}","starred_url":"https://api.github.com/users/Industrial/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Industrial/subscriptions","organizations_url":"https://api.github.com/users/Industrial/orgs","repos_url":"https://api.github.com/users/Industrial/repos","events_url":"https://api.github.com/users/Industrial/events{/privacy}","received_events_url":"https://api.github.com/users/Industrial/received_events","type":"User","site_admin":false},"created_at":"2018-09-15T19:07:15Z","updated_at":"2018-09-15T19:07:15Z","author_association":"NONE","body":"Would love to see this."}}
{"actor":{"display_login":"Industrial"}}