{"action":"created","comment":{"url":"https://api.github.com/repos/mmmries/sqlitex/pulls/comments/30222162","id":30222162,"diff_hunk":"@@ -0,0 +1,74 @@\n+defmodule Sqlitex.SqlBuilder do\n+  @moduledoc \"\"\"\n+  This module contains functions for SQL creation. At the moment\n+  it is only used for `CREATE TABLE` statements.\n+  \"\"\"\n+  \n+  # Supported table options\n+  defp table_opt(:temporary), do: {:temp, \"TEMP\"}\n+  defp table_opt(:temp), do: {:temp, \"TEMP\"}\n+\n+  defp table_opt({:primary_key, cols}) when is_list(cols) do\n+    {:primary_key, \",PRIMARY KEY (\" <> Enum.join(cols, \",\") <> \")\"}\n+  end\n+\n+  defp table_opt({:primary_key, col}) when is_atom(col) do\n+    {:primary_key, \",PRIMARY KEY (\" <> Atom.to_string(col) <> \")\"}\n+  end\n+\n+  # Catch invalid / unsupported table options\n+  defp table_opt(opt), do: raise \"Unkown table option: #{IO.inspect(opt)}\"","path":"lib/sqlitex/sql_builder.ex","position":20,"original_position":20,"commit_id":"0ddb3ce22f6543d6c9a86f463ee608e9f7692ebe","original_commit_id":"0ddb3ce22f6543d6c9a86f463ee608e9f7692ebe","user":{"login":"jazzyb","id":52593,"avatar_url":"https://avatars.githubusercontent.com/u/52593?v=3","gravatar_id":"","url":"https://api.github.com/users/jazzyb","html_url":"https://github.com/jazzyb","followers_url":"https://api.github.com/users/jazzyb/followers","following_url":"https://api.github.com/users/jazzyb/following{/other_user}","gists_url":"https://api.github.com/users/jazzyb/gists{/gist_id}","starred_url":"https://api.github.com/users/jazzyb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jazzyb/subscriptions","organizations_url":"https://api.github.com/users/jazzyb/orgs","repos_url":"https://api.github.com/users/jazzyb/repos","events_url":"https://api.github.com/users/jazzyb/events{/privacy}","received_events_url":"https://api.github.com/users/jazzyb/received_events","type":"User","site_admin":false},"body":"You don't need to raise an error here.  Unmatched arguments will raise runtime exceptions anyway.","created_at":"2015-05-13T11:33:55Z","updated_at":"2015-05-13T11:33:55Z","html_url":"https://github.com/mmmries/sqlitex/pull/9#discussion_r30222162","pull_request_url":"https://api.github.com/repos/mmmries/sqlitex/pulls/9","_links":{"self":{"href":"https://api.github.com/repos/mmmries/sqlitex/pulls/comments/30222162"},"html":{"href":"https://github.com/mmmries/sqlitex/pull/9#discussion_r30222162"},"pull_request":{"href":"https://api.github.com/repos/mmmries/sqlitex/pulls/9"}}},"pull_request":{"url":"https://api.github.com/repos/mmmries/sqlitex/pulls/9","id":34760620,"html_url":"https://github.com/mmmries/sqlitex/pull/9","diff_url":"https://github.com/mmmries/sqlitex/pull/9.diff","patch_url":"https://github.com/mmmries/sqlitex/pull/9.patch","issue_url":"https://api.github.com/repos/mmmries/sqlitex/issues/9","number":9,"state":"open","locked":false,"title":"Added a nice way to create tables","user":{"login":"pb82","id":1851198,"avatar_url":"https://avatars.githubusercontent.com/u/1851198?v=3","gravatar_id":"","url":"https://api.github.com/users/pb82","html_url":"https://github.com/pb82","followers_url":"https://api.github.com/users/pb82/followers","following_url":"https://api.github.com/users/pb82/following{/other_user}","gists_url":"https://api.github.com/users/pb82/gists{/gist_id}","starred_url":"https://api.github.com/users/pb82/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pb82/subscriptions","organizations_url":"https://api.github.com/users/pb82/orgs","repos_url":"https://api.github.com/users/pb82/repos","events_url":"https://api.github.com/users/pb82/events{/privacy}","received_events_url":"https://api.github.com/users/pb82/received_events","type":"User","site_admin":false},"body":"I thought it would be useful to have a nice way of creating tables, so I added a function to do this. The table definition is passed as a keyword list, like:\r\n\r\n```elixir\r\nSqlitex.create(db, \"users\", id: :integer, name: :text)\r\n```\r\n\r\nSince sqlite does not have types, i don't validate them. Sqlite literally allows you to pass anything as column type and it will choose an affinity based on some rules (https://www.sqlite.org/datatype3.html). Column names and types are only required to be passed as atoms.\r\n\r\nI've also added a test and extended the server api. Let me know what you think,\r\n\r\nThanks!","created_at":"2015-05-05T19:55:13Z","updated_at":"2015-05-13T11:33:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d748d6137d6a2c596a85f75f3085fd0b2d085251","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mmmries/sqlitex/pulls/9/commits","review_comments_url":"https://api.github.com/repos/mmmries/sqlitex/pulls/9/comments","review_comment_url":"https://api.github.com/repos/mmmries/sqlitex/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mmmries/sqlitex/issues/9/comments","statuses_url":"https://api.github.com/repos/mmmries/sqlitex/statuses/0ddb3ce22f6543d6c9a86f463ee608e9f7692ebe","head":{"label":"pb82:feature_create_db","ref":"feature_create_db","sha":"0ddb3ce22f6543d6c9a86f463ee608e9f7692ebe","user":{"login":"pb82","id":1851198,"avatar_url":"https://avatars.githubusercontent.com/u/1851198?v=3","gravatar_id":"","url":"https://api.github.com/users/pb82","html_url":"https://github.com/pb82","followers_url":"https://api.github.com/users/pb82/followers","following_url":"https://api.github.com/users/pb82/following{/other_user}","gists_url":"https://api.github.com/users/pb82/gists{/gist_id}","starred_url":"https://api.github.com/users/pb82/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pb82/subscriptions","organizations_url":"https://api.github.com/users/pb82/orgs","repos_url":"https://api.github.com/users/pb82/repos","events_url":"https://api.github.com/users/pb82/events{/privacy}","received_events_url":"https://api.github.com/users/pb82/received_events","type":"User","site_admin":false},"repo":{"id":33942432,"name":"sqlitex","full_name":"pb82/sqlitex","owner":{"login":"pb82","id":1851198,"avatar_url":"https://avatars.githubusercontent.com/u/1851198?v=3","gravatar_id":"","url":"https://api.github.com/users/pb82","html_url":"https://github.com/pb82","followers_url":"https://api.github.com/users/pb82/followers","following_url":"https://api.github.com/users/pb82/following{/other_user}","gists_url":"https://api.github.com/users/pb82/gists{/gist_id}","starred_url":"https://api.github.com/users/pb82/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pb82/subscriptions","organizations_url":"https://api.github.com/users/pb82/orgs","repos_url":"https://api.github.com/users/pb82/repos","events_url":"https://api.github.com/users/pb82/events{/privacy}","received_events_url":"https://api.github.com/users/pb82/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pb82/sqlitex","description":"An Elixir wrapper around esqlite. Allows access to sqlite3 databases.","fork":true,"url":"https://api.github.com/repos/pb82/sqlitex","forks_url":"https://api.github.com/repos/pb82/sqlitex/forks","keys_url":"https://api.github.com/repos/pb82/sqlitex/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pb82/sqlitex/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pb82/sqlitex/teams","hooks_url":"https://api.github.com/repos/pb82/sqlitex/hooks","issue_events_url":"https://api.github.com/repos/pb82/sqlitex/issues/events{/number}","events_url":"https://api.github.com/repos/pb82/sqlitex/events","assignees_url":"https://api.github.com/repos/pb82/sqlitex/assignees{/user}","branches_url":"https://api.github.com/repos/pb82/sqlitex/branches{/branch}","tags_url":"https://api.github.com/repos/pb82/sqlitex/tags","blobs_url":"https://api.github.com/repos/pb82/sqlitex/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pb82/sqlitex/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pb82/sqlitex/git/refs{/sha}","trees_url":"https://api.github.com/repos/pb82/sqlitex/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pb82/sqlitex/statuses/{sha}","languages_url":"https://api.github.com/repos/pb82/sqlitex/languages","stargazers_url":"https://api.github.com/repos/pb82/sqlitex/stargazers","contributors_url":"https://api.github.com/repos/pb82/sqlitex/contributors","subscribers_url":"https://api.github.com/repos/pb82/sqlitex/subscribers","subscription_url":"https://api.github.com/repos/pb82/sqlitex/subscription","commits_url":"https://api.github.com/repos/pb82/sqlitex/commits{/sha}","git_commits_url":"https://api.github.com/repos/pb82/sqlitex/git/commits{/sha}","comments_url":"https://api.github.com/repos/pb82/sqlitex/comments{/number}","issue_comment_url":"https://api.github.com/repos/pb82/sqlitex/issues/comments{/number}","contents_url":"https://api.github.com/repos/pb82/sqlitex/contents/{+path}","compare_url":"https://api.github.com/repos/pb82/sqlitex/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pb82/sqlitex/merges","archive_url":"https://api.github.com/repos/pb82/sqlitex/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pb82/sqlitex/downloads","issues_url":"https://api.github.com/repos/pb82/sqlitex/issues{/number}","pulls_url":"https://api.github.com/repos/pb82/sqlitex/pulls{/number}","milestones_url":"https://api.github.com/repos/pb82/sqlitex/milestones{/number}","notifications_url":"https://api.github.com/repos/pb82/sqlitex/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pb82/sqlitex/labels{/name}","releases_url":"https://api.github.com/repos/pb82/sqlitex/releases{/id}","created_at":"2015-04-14T16:08:32Z","updated_at":"2015-04-14T16:08:32Z","pushed_at":"2015-05-10T18:12:32Z","git_url":"git://github.com/pb82/sqlitex.git","ssh_url":"git@github.com:pb82/sqlitex.git","clone_url":"https://github.com/pb82/sqlitex.git","svn_url":"https://github.com/pb82/sqlitex","homepage":"https://hex.pm/packages/sqlitex","size":134,"stargazers_count":0,"watchers_count":0,"language":"Elixir","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":"mmmries:master","ref":"master","sha":"47dfbd9a45f9f463a727380ef5f732e46284f9d9","user":{"login":"mmmries","id":80008,"avatar_url":"https://avatars.githubusercontent.com/u/80008?v=3","gravatar_id":"","url":"https://api.github.com/users/mmmries","html_url":"https://github.com/mmmries","followers_url":"https://api.github.com/users/mmmries/followers","following_url":"https://api.github.com/users/mmmries/following{/other_user}","gists_url":"https://api.github.com/users/mmmries/gists{/gist_id}","starred_url":"https://api.github.com/users/mmmries/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mmmries/subscriptions","organizations_url":"https://api.github.com/users/mmmries/orgs","repos_url":"https://api.github.com/users/mmmries/repos","events_url":"https://api.github.com/users/mmmries/events{/privacy}","received_events_url":"https://api.github.com/users/mmmries/received_events","type":"User","site_admin":false},"repo":{"id":29835967,"name":"sqlitex","full_name":"mmmries/sqlitex","owner":{"login":"mmmries","id":80008,"avatar_url":"https://avatars.githubusercontent.com/u/80008?v=3","gravatar_id":"","url":"https://api.github.com/users/mmmries","html_url":"https://github.com/mmmries","followers_url":"https://api.github.com/users/mmmries/followers","following_url":"https://api.github.com/users/mmmries/following{/other_user}","gists_url":"https://api.github.com/users/mmmries/gists{/gist_id}","starred_url":"https://api.github.com/users/mmmries/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mmmries/subscriptions","organizations_url":"https://api.github.com/users/mmmries/orgs","repos_url":"https://api.github.com/users/mmmries/repos","events_url":"https://api.github.com/users/mmmries/events{/privacy}","received_events_url":"https://api.github.com/users/mmmries/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mmmries/sqlitex","description":"An Elixir wrapper around esqlite. Allows access to sqlite3 databases.","fork":false,"url":"https://api.github.com/repos/mmmries/sqlitex","forks_url":"https://api.github.com/repos/mmmries/sqlitex/forks","keys_url":"https://api.github.com/repos/mmmries/sqlitex/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mmmries/sqlitex/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mmmries/sqlitex/teams","hooks_url":"https://api.github.com/repos/mmmries/sqlitex/hooks","issue_events_url":"https://api.github.com/repos/mmmries/sqlitex/issues/events{/number}","events_url":"https://api.github.com/repos/mmmries/sqlitex/events","assignees_url":"https://api.github.com/repos/mmmries/sqlitex/assignees{/user}","branches_url":"https://api.github.com/repos/mmmries/sqlitex/branches{/branch}","tags_url":"https://api.github.com/repos/mmmries/sqlitex/tags","blobs_url":"https://api.github.com/repos/mmmries/sqlitex/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mmmries/sqlitex/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mmmries/sqlitex/git/refs{/sha}","trees_url":"https://api.github.com/repos/mmmries/sqlitex/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mmmries/sqlitex/statuses/{sha}","languages_url":"https://api.github.com/repos/mmmries/sqlitex/languages","stargazers_url":"https://api.github.com/repos/mmmries/sqlitex/stargazers","contributors_url":"https://api.github.com/repos/mmmries/sqlitex/contributors","subscribers_url":"https://api.github.com/repos/mmmries/sqlitex/subscribers","subscription_url":"https://api.github.com/repos/mmmries/sqlitex/subscription","commits_url":"https://api.github.com/repos/mmmries/sqlitex/commits{/sha}","git_commits_url":"https://api.github.com/repos/mmmries/sqlitex/git/commits{/sha}","comments_url":"https://api.github.com/repos/mmmries/sqlitex/comments{/number}","issue_comment_url":"https://api.github.com/repos/mmmries/sqlitex/issues/comments{/number}","contents_url":"https://api.github.com/repos/mmmries/sqlitex/contents/{+path}","compare_url":"https://api.github.com/repos/mmmries/sqlitex/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mmmries/sqlitex/merges","archive_url":"https://api.github.com/repos/mmmries/sqlitex/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mmmries/sqlitex/downloads","issues_url":"https://api.github.com/repos/mmmries/sqlitex/issues{/number}","pulls_url":"https://api.github.com/repos/mmmries/sqlitex/pulls{/number}","milestones_url":"https://api.github.com/repos/mmmries/sqlitex/milestones{/number}","notifications_url":"https://api.github.com/repos/mmmries/sqlitex/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mmmries/sqlitex/labels{/name}","releases_url":"https://api.github.com/repos/mmmries/sqlitex/releases{/id}","created_at":"2015-01-25T23:19:33Z","updated_at":"2015-05-05T03:28:38Z","pushed_at":"2015-05-12T15:21:32Z","git_url":"git://github.com/mmmries/sqlitex.git","ssh_url":"git@github.com:mmmries/sqlitex.git","clone_url":"https://github.com/mmmries/sqlitex.git","svn_url":"https://github.com/mmmries/sqlitex","homepage":"https://hex.pm/packages/sqlitex","size":365,"stargazers_count":4,"watchers_count":4,"language":"Elixir","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":3,"forks":4,"open_issues":3,"watchers":4,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mmmries/sqlitex/pulls/9"},"html":{"href":"https://github.com/mmmries/sqlitex/pull/9"},"issue":{"href":"https://api.github.com/repos/mmmries/sqlitex/issues/9"},"comments":{"href":"https://api.github.com/repos/mmmries/sqlitex/issues/9/comments"},"review_comments":{"href":"https://api.github.com/repos/mmmries/sqlitex/pulls/9/comments"},"review_comment":{"href":"https://api.github.com/repos/mmmries/sqlitex/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mmmries/sqlitex/pulls/9/commits"},"statuses":{"href":"https://api.github.com/repos/mmmries/sqlitex/statuses/0ddb3ce22f6543d6c9a86f463ee608e9f7692ebe"}}}}