{"action":"created","comment":{"url":"https://api.github.com/repos/amberframework/granite-orm/pulls/comments/178311306","pull_request_review_id":108357120,"id":178311306,"diff_hunk":"@@ -76,6 +76,31 @@ class Granite::Adapter::Mysql < Granite::Adapter::Base\n     end\n   end\n \n+  def import(table_name, primary_name, primary_auto, fields, model_array)\n+  statement = String.build do |stmt|\n+    stmt << \"INSERT INTO #{quote(table_name)} (\"\n+    stmt << \"#{quote(primary_name)}, \" unless primary_auto\n+    stmt << fields.map { |field| quote(field) }.join(\", \")\n+    stmt << \") VALUES \"\n+\n+    model_array.each do |model|\n+      if model.responds_to? :to_h\n+        next unless model.valid?\n+        stmt << \"(\"\n+        stmt << model.to_h[primary_name].to_s + \", \" unless primary_auto\n+        stmt << fields.map { |field| model.to_h[field].is_a?(String) ? \"'\" + model.to_h[field].to_s + \"'\" : model.to_h[field] }.join(\", \")","path":"src/adapter/mysql.cr","position":16,"original_position":16,"commit_id":"814de94b1b5b754efea4f3c09604be7acf153e1d","original_commit_id":"814de94b1b5b754efea4f3c09604be7acf153e1d","user":{"login":"Blacksmoke16","id":12136995,"avatar_url":"https://avatars1.githubusercontent.com/u/12136995?v=4","gravatar_id":"","url":"https://api.github.com/users/Blacksmoke16","html_url":"https://github.com/Blacksmoke16","followers_url":"https://api.github.com/users/Blacksmoke16/followers","following_url":"https://api.github.com/users/Blacksmoke16/following{/other_user}","gists_url":"https://api.github.com/users/Blacksmoke16/gists{/gist_id}","starred_url":"https://api.github.com/users/Blacksmoke16/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Blacksmoke16/subscriptions","organizations_url":"https://api.github.com/users/Blacksmoke16/orgs","repos_url":"https://api.github.com/users/Blacksmoke16/repos","events_url":"https://api.github.com/users/Blacksmoke16/events{/privacy}","received_events_url":"https://api.github.com/users/Blacksmoke16/received_events","type":"User","site_admin":false},"body":"The quoting method I do use for column/table names. However, since it quotes with the backtick that couldn't be used for string values afaik?","created_at":"2018-03-30T15:25:19Z","updated_at":"2018-03-30T15:25:20Z","html_url":"https://github.com/amberframework/granite-orm/pull/168#discussion_r178311306","pull_request_url":"https://api.github.com/repos/amberframework/granite-orm/pulls/168","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/amberframework/granite-orm/pulls/comments/178311306"},"html":{"href":"https://github.com/amberframework/granite-orm/pull/168#discussion_r178311306"},"pull_request":{"href":"https://api.github.com/repos/amberframework/granite-orm/pulls/168"}},"in_reply_to_id":178224332},"pull_request":{"url":"https://api.github.com/repos/amberframework/granite-orm/pulls/168","id":178483808,"html_url":"https://github.com/amberframework/granite-orm/pull/168","diff_url":"https://github.com/amberframework/granite-orm/pull/168.diff","patch_url":"https://github.com/amberframework/granite-orm/pull/168.patch","issue_url":"https://api.github.com/repos/amberframework/granite-orm/issues/168","number":168,"state":"open","locked":false,"title":"[WIP] Bulk import","user":{"login":"Blacksmoke16","id":12136995,"avatar_url":"https://avatars1.githubusercontent.com/u/12136995?v=4","gravatar_id":"","url":"https://api.github.com/users/Blacksmoke16","html_url":"https://github.com/Blacksmoke16","followers_url":"https://api.github.com/users/Blacksmoke16/followers","following_url":"https://api.github.com/users/Blacksmoke16/following{/other_user}","gists_url":"https://api.github.com/users/Blacksmoke16/gists{/gist_id}","starred_url":"https://api.github.com/users/Blacksmoke16/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Blacksmoke16/subscriptions","organizations_url":"https://api.github.com/users/Blacksmoke16/orgs","repos_url":"https://api.github.com/users/Blacksmoke16/repos","events_url":"https://api.github.com/users/Blacksmoke16/events{/privacy}","received_events_url":"https://api.github.com/users/Blacksmoke16/received_events","type":"User","site_admin":false},"body":"PR for #156 \r\n\r\n## Progress\r\n- [x] Create method/initial MySQL adapter code\r\n- [ ] Find a better way to handle quoting of String datatypes.\r\n- [ ] Test with various MySQL/granite datatypes\r\n- [ ] Handle lifecycle events\r\n- [ ] Handle ON DUPLICATE KEY UPDATE/IGNORE\r\n- [ ] Add Postgres/sqlite adapter versions\r\n- [ ] Add tests\r\n\r\n## Questions:\r\n\r\n1. How should the lifecycle hooks be handled? \r\nEither, hooks would _not_ run for each model being inserted, but would get triggered once all are inserted and such.\r\n\r\n","created_at":"2018-03-30T02:46:59Z","updated_at":"2018-03-30T15:25:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1c954593075aabf99b5d4b1cd572ebf255c6d655","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/amberframework/granite-orm/pulls/168/commits","review_comments_url":"https://api.github.com/repos/amberframework/granite-orm/pulls/168/comments","review_comment_url":"https://api.github.com/repos/amberframework/granite-orm/pulls/comments{/number}","comments_url":"https://api.github.com/repos/amberframework/granite-orm/issues/168/comments","statuses_url":"https://api.github.com/repos/amberframework/granite-orm/statuses/814de94b1b5b754efea4f3c09604be7acf153e1d","head":{"label":"Blacksmoke16:bulk-import","ref":"bulk-import","sha":"814de94b1b5b754efea4f3c09604be7acf153e1d","user":{"login":"Blacksmoke16","id":12136995,"avatar_url":"https://avatars1.githubusercontent.com/u/12136995?v=4","gravatar_id":"","url":"https://api.github.com/users/Blacksmoke16","html_url":"https://github.com/Blacksmoke16","followers_url":"https://api.github.com/users/Blacksmoke16/followers","following_url":"https://api.github.com/users/Blacksmoke16/following{/other_user}","gists_url":"https://api.github.com/users/Blacksmoke16/gists{/gist_id}","starred_url":"https://api.github.com/users/Blacksmoke16/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Blacksmoke16/subscriptions","organizations_url":"https://api.github.com/users/Blacksmoke16/orgs","repos_url":"https://api.github.com/users/Blacksmoke16/repos","events_url":"https://api.github.com/users/Blacksmoke16/events{/privacy}","received_events_url":"https://api.github.com/users/Blacksmoke16/received_events","type":"User","site_admin":false},"repo":{"id":127354815,"name":"granite-orm","full_name":"Blacksmoke16/granite-orm","owner":{"login":"Blacksmoke16","id":12136995,"avatar_url":"https://avatars1.githubusercontent.com/u/12136995?v=4","gravatar_id":"","url":"https://api.github.com/users/Blacksmoke16","html_url":"https://github.com/Blacksmoke16","followers_url":"https://api.github.com/users/Blacksmoke16/followers","following_url":"https://api.github.com/users/Blacksmoke16/following{/other_user}","gists_url":"https://api.github.com/users/Blacksmoke16/gists{/gist_id}","starred_url":"https://api.github.com/users/Blacksmoke16/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Blacksmoke16/subscriptions","organizations_url":"https://api.github.com/users/Blacksmoke16/orgs","repos_url":"https://api.github.com/users/Blacksmoke16/repos","events_url":"https://api.github.com/users/Blacksmoke16/events{/privacy}","received_events_url":"https://api.github.com/users/Blacksmoke16/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Blacksmoke16/granite-orm","description":"ORM Model with Adapters for mysql, pg, sqlite in the Crystal Language.","fork":true,"url":"https://api.github.com/repos/Blacksmoke16/granite-orm","forks_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/forks","keys_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/teams","hooks_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/hooks","issue_events_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/issues/events{/number}","events_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/events","assignees_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/assignees{/user}","branches_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/branches{/branch}","tags_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/tags","blobs_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/git/refs{/sha}","trees_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/statuses/{sha}","languages_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/languages","stargazers_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/stargazers","contributors_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/contributors","subscribers_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/subscribers","subscription_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/subscription","commits_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/commits{/sha}","git_commits_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/git/commits{/sha}","comments_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/comments{/number}","issue_comment_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/issues/comments{/number}","contents_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/contents/{+path}","compare_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/merges","archive_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/downloads","issues_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/issues{/number}","pulls_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/pulls{/number}","milestones_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/milestones{/number}","notifications_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/labels{/name}","releases_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/releases{/id}","deployments_url":"https://api.github.com/repos/Blacksmoke16/granite-orm/deployments","created_at":"2018-03-29T22:43:07Z","updated_at":"2018-03-29T22:43:09Z","pushed_at":"2018-03-30T02:42:27Z","git_url":"git://github.com/Blacksmoke16/granite-orm.git","ssh_url":"git@github.com:Blacksmoke16/granite-orm.git","clone_url":"https://github.com/Blacksmoke16/granite-orm.git","svn_url":"https://github.com/Blacksmoke16/granite-orm","homepage":"","size":585,"stargazers_count":0,"watchers_count":0,"language":"Crystal","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"amberframework:master","ref":"master","sha":"5808e1c1f675f4404b757781ace5f99b196f0981","user":{"login":"amberframework","id":27691024,"avatar_url":"https://avatars1.githubusercontent.com/u/27691024?v=4","gravatar_id":"","url":"https://api.github.com/users/amberframework","html_url":"https://github.com/amberframework","followers_url":"https://api.github.com/users/amberframework/followers","following_url":"https://api.github.com/users/amberframework/following{/other_user}","gists_url":"https://api.github.com/users/amberframework/gists{/gist_id}","starred_url":"https://api.github.com/users/amberframework/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amberframework/subscriptions","organizations_url":"https://api.github.com/users/amberframework/orgs","repos_url":"https://api.github.com/users/amberframework/repos","events_url":"https://api.github.com/users/amberframework/events{/privacy}","received_events_url":"https://api.github.com/users/amberframework/received_events","type":"Organization","site_admin":false},"repo":{"id":41196214,"name":"granite-orm","full_name":"amberframework/granite-orm","owner":{"login":"amberframework","id":27691024,"avatar_url":"https://avatars1.githubusercontent.com/u/27691024?v=4","gravatar_id":"","url":"https://api.github.com/users/amberframework","html_url":"https://github.com/amberframework","followers_url":"https://api.github.com/users/amberframework/followers","following_url":"https://api.github.com/users/amberframework/following{/other_user}","gists_url":"https://api.github.com/users/amberframework/gists{/gist_id}","starred_url":"https://api.github.com/users/amberframework/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amberframework/subscriptions","organizations_url":"https://api.github.com/users/amberframework/orgs","repos_url":"https://api.github.com/users/amberframework/repos","events_url":"https://api.github.com/users/amberframework/events{/privacy}","received_events_url":"https://api.github.com/users/amberframework/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/amberframework/granite-orm","description":"ORM Model with Adapters for mysql, pg, sqlite in the Crystal Language.","fork":false,"url":"https://api.github.com/repos/amberframework/granite-orm","forks_url":"https://api.github.com/repos/amberframework/granite-orm/forks","keys_url":"https://api.github.com/repos/amberframework/granite-orm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/amberframework/granite-orm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/amberframework/granite-orm/teams","hooks_url":"https://api.github.com/repos/amberframework/granite-orm/hooks","issue_events_url":"https://api.github.com/repos/amberframework/granite-orm/issues/events{/number}","events_url":"https://api.github.com/repos/amberframework/granite-orm/events","assignees_url":"https://api.github.com/repos/amberframework/granite-orm/assignees{/user}","branches_url":"https://api.github.com/repos/amberframework/granite-orm/branches{/branch}","tags_url":"https://api.github.com/repos/amberframework/granite-orm/tags","blobs_url":"https://api.github.com/repos/amberframework/granite-orm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/amberframework/granite-orm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/amberframework/granite-orm/git/refs{/sha}","trees_url":"https://api.github.com/repos/amberframework/granite-orm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/amberframework/granite-orm/statuses/{sha}","languages_url":"https://api.github.com/repos/amberframework/granite-orm/languages","stargazers_url":"https://api.github.com/repos/amberframework/granite-orm/stargazers","contributors_url":"https://api.github.com/repos/amberframework/granite-orm/contributors","subscribers_url":"https://api.github.com/repos/amberframework/granite-orm/subscribers","subscription_url":"https://api.github.com/repos/amberframework/granite-orm/subscription","commits_url":"https://api.github.com/repos/amberframework/granite-orm/commits{/sha}","git_commits_url":"https://api.github.com/repos/amberframework/granite-orm/git/commits{/sha}","comments_url":"https://api.github.com/repos/amberframework/granite-orm/comments{/number}","issue_comment_url":"https://api.github.com/repos/amberframework/granite-orm/issues/comments{/number}","contents_url":"https://api.github.com/repos/amberframework/granite-orm/contents/{+path}","compare_url":"https://api.github.com/repos/amberframework/granite-orm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/amberframework/granite-orm/merges","archive_url":"https://api.github.com/repos/amberframework/granite-orm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/amberframework/granite-orm/downloads","issues_url":"https://api.github.com/repos/amberframework/granite-orm/issues{/number}","pulls_url":"https://api.github.com/repos/amberframework/granite-orm/pulls{/number}","milestones_url":"https://api.github.com/repos/amberframework/granite-orm/milestones{/number}","notifications_url":"https://api.github.com/repos/amberframework/granite-orm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/amberframework/granite-orm/labels{/name}","releases_url":"https://api.github.com/repos/amberframework/granite-orm/releases{/id}","deployments_url":"https://api.github.com/repos/amberframework/granite-orm/deployments","created_at":"2015-08-22T07:28:16Z","updated_at":"2018-03-28T03:41:41Z","pushed_at":"2018-03-30T02:47:00Z","git_url":"git://github.com/amberframework/granite-orm.git","ssh_url":"git@github.com:amberframework/granite-orm.git","clone_url":"https://github.com/amberframework/granite-orm.git","svn_url":"https://github.com/amberframework/granite-orm","homepage":"","size":587,"stargazers_count":102,"watchers_count":102,"language":"Crystal","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":33,"mirror_url":null,"archived":false,"open_issues_count":25,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":33,"open_issues":25,"watchers":102,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/amberframework/granite-orm/pulls/168"},"html":{"href":"https://github.com/amberframework/granite-orm/pull/168"},"issue":{"href":"https://api.github.com/repos/amberframework/granite-orm/issues/168"},"comments":{"href":"https://api.github.com/repos/amberframework/granite-orm/issues/168/comments"},"review_comments":{"href":"https://api.github.com/repos/amberframework/granite-orm/pulls/168/comments"},"review_comment":{"href":"https://api.github.com/repos/amberframework/granite-orm/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/amberframework/granite-orm/pulls/168/commits"},"statuses":{"href":"https://api.github.com/repos/amberframework/granite-orm/statuses/814de94b1b5b754efea4f3c09604be7acf153e1d"}},"author_association":"NONE"}}
{"actor":{"display_login":"Blacksmoke16"}}