{"action":"created","comment":{"url":"https://api.github.com/repos/ncalexan/datomish/pulls/comments/76710387","id":76710387,"diff_hunk":"@@ -164,6 +167,324 @@\n      :table-alias source/gensym-table-alias\n      :make-constraints nil}))\n \n+(defn- retractions->queries [retractions tx fulltext? ->SQLite]\n+  (let\n+    [f-q\n+     \"WITH vv AS (SELECT rowid FROM fulltext_values WHERE text = ?)\n+     INSERT INTO tx_lookup (e0, a0, v0, tx0, added0, value_type_tag0, sv, svalue_type_tag)\n+     VALUES (?, ?, (SELECT rowid FROM vv), ?, 0, ?, (SELECT rowid FROM vv), ?)\"\n+\n+     non-f-q\n+     \"INSERT INTO tx_lookup (e0, a0, v0, tx0, added0, value_type_tag0, sv, svalue_type_tag)\n+     VALUES (?, ?, ?, ?, 0, ?, ?, ?)\"]\n+    (map\n+      (fn [[_ e a v]]\n+        (let [[v tag] (->SQLite a v)]\n+          (if (fulltext? a)\n+            [f-q\n+             v e a tx tag tag]\n+            [non-f-q\n+             e a v tx tag v tag])))\n+      retractions)))\n+\n+(defn- non-fts-many->queries [ops tx ->SQLite indexing? ref? unique?]\n+  (let [q \"INSERT INTO tx_lookup (e0, a0, v0, tx0, added0, value_type_tag0, index_avet0, index_vaet0, index_fulltext0, unique_value0, sv, svalue_type_tag) VALUES \"\n+\n+        values-part\n+        ;; e0, a0, v0, tx0, added0, value_type_tag0\n+        ;; index_avet0, index_vaet0, index_fulltext0,\n+        ;; unique_value0, sv, svalue_type_tag\n+        \"(?, ?, ?, ?, 1, ?, ?, ?, 0, ?, ?, ?)\"\n+\n+        repeater (memoize (fn [n] (interpose \", \" (repeat n values-part))))]\n+\n+    ;; This query takes ten variables per item. So we partition into max-sql-vars / 10.\n+    (map\n+      (fn [chunk]\n+        (cons\n+          ;; Query string.\n+          (apply str q (repeater (count chunk)))\n+\n+          ;; Bindings.\n+          (mapcat (fn [[_ e a v]]\n+                    (let [[v tag] (->SQLite a v)]\n+                      [e a v tx tag\n+                       (indexing? a)      ; index_avet\n+                       (ref? a)           ; index_vaet\n+                       (unique? a)        ; unique_value\n+                       v tag]))\n+                  chunk)))\n+\n+      (partition-all (quot max-sql-vars 10) ops))))\n+\n+(defn- non-fts-one->queries [ops tx ->SQLite indexing? ref? unique?]\n+  (let [first-values-part\n+        ;; TODO: order value and tag closer together.\n+        ;; flags0\n+        ;; sv, svalue_type_tag\n+        \"(?, ?, ?, ?, ?, ?, ?, ?, 0, ?, ?, ?)\"\n+        first-repeater (memoize (fn [n] (interpose \", \" (repeat n first-values-part))))\n+\n+        second-values-part\n+        \"(?, ?, ?, ?, ?, ?)\"\n+        second-repeater (memoize (fn [n] (interpose \", \" (repeat n second-values-part))))\n+        ]\n+\n+    ;; :db.cardinality/one takes two queries.\n+    (mapcat\n+      (fn [chunk]\n+        [(cons\n+           (apply\n+             str\n+             \"INSERT INTO tx_lookup (e0, a0, v0, tx0, added0, value_type_tag0, index_avet0, index_vaet0, index_fulltext0, unique_value0, sv, svalue_type_tag) VALUES \"\n+             (first-repeater (count chunk)))\n+           (mapcat (fn [[_ e a v]]\n+                     (let [[v tag] (->SQLite a v)]\n+                       [e a v tx 1 tag\n+                        (indexing? a)   ; index_avet\n+                        (ref? a)        ; index_vaet\n+                        (unique? a)     ; unique_value\n+                        v tag]))\n+                   chunk))\n+\n+         (cons\n+           (apply\n+             str\n+             \"INSERT INTO tx_lookup (e0, a0, v0, tx0, added0, value_type_tag0) VALUES \"\n+             (second-repeater (count chunk)))\n+           (mapcat (fn [[_ e a v]]\n+                     (let [[v tag] (->SQLite a v)]\n+                       [e a v tx 0 tag]))\n+                   chunk))])\n+      (partition-all (quot max-sql-vars 11) ops))))\n+\n+;;; An FTS insertion happens in two parts.\n+;;; Firstly, we ensure that the fulltext value is present in the store.\n+;;; This is effectively an INSERT OR IGNORE… but FTS tables don't support\n+;;; uniqueness constraints. So we do it through a trigger on a view.\n+;;; When we insert the value, we pass with it a searchid. We'll use this","path":"src/datomish/db.cljc","position":231,"original_position":118,"commit_id":"87a0a79d5ed6b451a7a3d57fbf0b37bfe53a720a","original_commit_id":"bda67ac8e804b24dc0d32ef02c1a677d52c648c1","user":{"login":"ncalexan","id":1097182,"avatar_url":"https://avatars.githubusercontent.com/u/1097182?v=3","gravatar_id":"","url":"https://api.github.com/users/ncalexan","html_url":"https://github.com/ncalexan","followers_url":"https://api.github.com/users/ncalexan/followers","following_url":"https://api.github.com/users/ncalexan/following{/other_user}","gists_url":"https://api.github.com/users/ncalexan/gists{/gist_id}","starred_url":"https://api.github.com/users/ncalexan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ncalexan/subscriptions","organizations_url":"https://api.github.com/users/ncalexan/orgs","repos_url":"https://api.github.com/users/ncalexan/repos","events_url":"https://api.github.com/users/ncalexan/events{/privacy}","received_events_url":"https://api.github.com/users/ncalexan/received_events","type":"User","site_admin":false},"body":"Worth stating that search IDs are transient; they're only good during one transaction.","created_at":"2016-08-30T00:04:50Z","updated_at":"2016-08-30T00:04:50Z","html_url":"https://github.com/ncalexan/datomish/pull/4#discussion_r76710387","pull_request_url":"https://api.github.com/repos/ncalexan/datomish/pulls/4","_links":{"self":{"href":"https://api.github.com/repos/ncalexan/datomish/pulls/comments/76710387"},"html":{"href":"https://github.com/ncalexan/datomish/pull/4#discussion_r76710387"},"pull_request":{"href":"https://api.github.com/repos/ncalexan/datomish/pulls/4"}}},"pull_request":{"url":"https://api.github.com/repos/ncalexan/datomish/pulls/4","id":83180427,"html_url":"https://github.com/ncalexan/datomish/pull/4","diff_url":"https://github.com/ncalexan/datomish/pull/4.diff","patch_url":"https://github.com/ncalexan/datomish/pull/4.patch","issue_url":"https://api.github.com/repos/ncalexan/datomish/issues/4","number":4,"state":"open","locked":false,"title":"Rnewman/joins","user":{"login":"ncalexan","id":1097182,"avatar_url":"https://avatars.githubusercontent.com/u/1097182?v=3","gravatar_id":"","url":"https://api.github.com/users/ncalexan","html_url":"https://github.com/ncalexan","followers_url":"https://api.github.com/users/ncalexan/followers","following_url":"https://api.github.com/users/ncalexan/following{/other_user}","gists_url":"https://api.github.com/users/ncalexan/gists{/gist_id}","starred_url":"https://api.github.com/users/ncalexan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ncalexan/subscriptions","organizations_url":"https://api.github.com/users/ncalexan/orgs","repos_url":"https://api.github.com/users/ncalexan/repos","events_url":"https://api.github.com/users/ncalexan/events{/privacy}","received_events_url":"https://api.github.com/users/ncalexan/received_events","type":"User","site_admin":false},"body":"@rnewman this PR culls my earlier commits; sorry for the noise.","created_at":"2016-08-29T22:41:12Z","updated_at":"2016-08-30T00:04:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/ncalexan/datomish/pulls/4/commits","review_comments_url":"https://api.github.com/repos/ncalexan/datomish/pulls/4/comments","review_comment_url":"https://api.github.com/repos/ncalexan/datomish/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ncalexan/datomish/issues/4/comments","statuses_url":"https://api.github.com/repos/ncalexan/datomish/statuses/87a0a79d5ed6b451a7a3d57fbf0b37bfe53a720a","head":{"label":"ncalexan:rnewman/joins","ref":"rnewman/joins","sha":"87a0a79d5ed6b451a7a3d57fbf0b37bfe53a720a","user":{"login":"ncalexan","id":1097182,"avatar_url":"https://avatars.githubusercontent.com/u/1097182?v=3","gravatar_id":"","url":"https://api.github.com/users/ncalexan","html_url":"https://github.com/ncalexan","followers_url":"https://api.github.com/users/ncalexan/followers","following_url":"https://api.github.com/users/ncalexan/following{/other_user}","gists_url":"https://api.github.com/users/ncalexan/gists{/gist_id}","starred_url":"https://api.github.com/users/ncalexan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ncalexan/subscriptions","organizations_url":"https://api.github.com/users/ncalexan/orgs","repos_url":"https://api.github.com/users/ncalexan/repos","events_url":"https://api.github.com/users/ncalexan/events{/privacy}","received_events_url":"https://api.github.com/users/ncalexan/received_events","type":"User","site_admin":false},"repo":{"id":62674602,"name":"datomish","full_name":"ncalexan/datomish","owner":{"login":"ncalexan","id":1097182,"avatar_url":"https://avatars.githubusercontent.com/u/1097182?v=3","gravatar_id":"","url":"https://api.github.com/users/ncalexan","html_url":"https://github.com/ncalexan","followers_url":"https://api.github.com/users/ncalexan/followers","following_url":"https://api.github.com/users/ncalexan/following{/other_user}","gists_url":"https://api.github.com/users/ncalexan/gists{/gist_id}","starred_url":"https://api.github.com/users/ncalexan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ncalexan/subscriptions","organizations_url":"https://api.github.com/users/ncalexan/orgs","repos_url":"https://api.github.com/users/ncalexan/repos","events_url":"https://api.github.com/users/ncalexan/events{/privacy}","received_events_url":"https://api.github.com/users/ncalexan/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ncalexan/datomish","description":"A persistent, relational store inspired by Datomic and DataScript.","fork":false,"url":"https://api.github.com/repos/ncalexan/datomish","forks_url":"https://api.github.com/repos/ncalexan/datomish/forks","keys_url":"https://api.github.com/repos/ncalexan/datomish/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ncalexan/datomish/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ncalexan/datomish/teams","hooks_url":"https://api.github.com/repos/ncalexan/datomish/hooks","issue_events_url":"https://api.github.com/repos/ncalexan/datomish/issues/events{/number}","events_url":"https://api.github.com/repos/ncalexan/datomish/events","assignees_url":"https://api.github.com/repos/ncalexan/datomish/assignees{/user}","branches_url":"https://api.github.com/repos/ncalexan/datomish/branches{/branch}","tags_url":"https://api.github.com/repos/ncalexan/datomish/tags","blobs_url":"https://api.github.com/repos/ncalexan/datomish/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ncalexan/datomish/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ncalexan/datomish/git/refs{/sha}","trees_url":"https://api.github.com/repos/ncalexan/datomish/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ncalexan/datomish/statuses/{sha}","languages_url":"https://api.github.com/repos/ncalexan/datomish/languages","stargazers_url":"https://api.github.com/repos/ncalexan/datomish/stargazers","contributors_url":"https://api.github.com/repos/ncalexan/datomish/contributors","subscribers_url":"https://api.github.com/repos/ncalexan/datomish/subscribers","subscription_url":"https://api.github.com/repos/ncalexan/datomish/subscription","commits_url":"https://api.github.com/repos/ncalexan/datomish/commits{/sha}","git_commits_url":"https://api.github.com/repos/ncalexan/datomish/git/commits{/sha}","comments_url":"https://api.github.com/repos/ncalexan/datomish/comments{/number}","issue_comment_url":"https://api.github.com/repos/ncalexan/datomish/issues/comments{/number}","contents_url":"https://api.github.com/repos/ncalexan/datomish/contents/{+path}","compare_url":"https://api.github.com/repos/ncalexan/datomish/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ncalexan/datomish/merges","archive_url":"https://api.github.com/repos/ncalexan/datomish/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ncalexan/datomish/downloads","issues_url":"https://api.github.com/repos/ncalexan/datomish/issues{/number}","pulls_url":"https://api.github.com/repos/ncalexan/datomish/pulls{/number}","milestones_url":"https://api.github.com/repos/ncalexan/datomish/milestones{/number}","notifications_url":"https://api.github.com/repos/ncalexan/datomish/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ncalexan/datomish/labels{/name}","releases_url":"https://api.github.com/repos/ncalexan/datomish/releases{/id}","deployments_url":"https://api.github.com/repos/ncalexan/datomish/deployments","created_at":"2016-07-05T22:48:01Z","updated_at":"2016-07-13T20:00:41Z","pushed_at":"2016-08-29T23:58:55Z","git_url":"git://github.com/ncalexan/datomish.git","ssh_url":"git@github.com:ncalexan/datomish.git","clone_url":"https://github.com/ncalexan/datomish.git","svn_url":"https://github.com/ncalexan/datomish","homepage":null,"size":279,"stargazers_count":1,"watchers_count":1,"language":"Clojure","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":3,"forks":0,"open_issues":3,"watchers":1,"default_branch":"master"}},"base":{"label":"ncalexan:joins","ref":"joins","sha":"57cd8a54eec78a2532e33bdab954d43b08c06d35","user":{"login":"ncalexan","id":1097182,"avatar_url":"https://avatars.githubusercontent.com/u/1097182?v=3","gravatar_id":"","url":"https://api.github.com/users/ncalexan","html_url":"https://github.com/ncalexan","followers_url":"https://api.github.com/users/ncalexan/followers","following_url":"https://api.github.com/users/ncalexan/following{/other_user}","gists_url":"https://api.github.com/users/ncalexan/gists{/gist_id}","starred_url":"https://api.github.com/users/ncalexan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ncalexan/subscriptions","organizations_url":"https://api.github.com/users/ncalexan/orgs","repos_url":"https://api.github.com/users/ncalexan/repos","events_url":"https://api.github.com/users/ncalexan/events{/privacy}","received_events_url":"https://api.github.com/users/ncalexan/received_events","type":"User","site_admin":false},"repo":{"id":62674602,"name":"datomish","full_name":"ncalexan/datomish","owner":{"login":"ncalexan","id":1097182,"avatar_url":"https://avatars.githubusercontent.com/u/1097182?v=3","gravatar_id":"","url":"https://api.github.com/users/ncalexan","html_url":"https://github.com/ncalexan","followers_url":"https://api.github.com/users/ncalexan/followers","following_url":"https://api.github.com/users/ncalexan/following{/other_user}","gists_url":"https://api.github.com/users/ncalexan/gists{/gist_id}","starred_url":"https://api.github.com/users/ncalexan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ncalexan/subscriptions","organizations_url":"https://api.github.com/users/ncalexan/orgs","repos_url":"https://api.github.com/users/ncalexan/repos","events_url":"https://api.github.com/users/ncalexan/events{/privacy}","received_events_url":"https://api.github.com/users/ncalexan/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ncalexan/datomish","description":"A persistent, relational store inspired by Datomic and DataScript.","fork":false,"url":"https://api.github.com/repos/ncalexan/datomish","forks_url":"https://api.github.com/repos/ncalexan/datomish/forks","keys_url":"https://api.github.com/repos/ncalexan/datomish/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ncalexan/datomish/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ncalexan/datomish/teams","hooks_url":"https://api.github.com/repos/ncalexan/datomish/hooks","issue_events_url":"https://api.github.com/repos/ncalexan/datomish/issues/events{/number}","events_url":"https://api.github.com/repos/ncalexan/datomish/events","assignees_url":"https://api.github.com/repos/ncalexan/datomish/assignees{/user}","branches_url":"https://api.github.com/repos/ncalexan/datomish/branches{/branch}","tags_url":"https://api.github.com/repos/ncalexan/datomish/tags","blobs_url":"https://api.github.com/repos/ncalexan/datomish/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ncalexan/datomish/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ncalexan/datomish/git/refs{/sha}","trees_url":"https://api.github.com/repos/ncalexan/datomish/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ncalexan/datomish/statuses/{sha}","languages_url":"https://api.github.com/repos/ncalexan/datomish/languages","stargazers_url":"https://api.github.com/repos/ncalexan/datomish/stargazers","contributors_url":"https://api.github.com/repos/ncalexan/datomish/contributors","subscribers_url":"https://api.github.com/repos/ncalexan/datomish/subscribers","subscription_url":"https://api.github.com/repos/ncalexan/datomish/subscription","commits_url":"https://api.github.com/repos/ncalexan/datomish/commits{/sha}","git_commits_url":"https://api.github.com/repos/ncalexan/datomish/git/commits{/sha}","comments_url":"https://api.github.com/repos/ncalexan/datomish/comments{/number}","issue_comment_url":"https://api.github.com/repos/ncalexan/datomish/issues/comments{/number}","contents_url":"https://api.github.com/repos/ncalexan/datomish/contents/{+path}","compare_url":"https://api.github.com/repos/ncalexan/datomish/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ncalexan/datomish/merges","archive_url":"https://api.github.com/repos/ncalexan/datomish/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ncalexan/datomish/downloads","issues_url":"https://api.github.com/repos/ncalexan/datomish/issues{/number}","pulls_url":"https://api.github.com/repos/ncalexan/datomish/pulls{/number}","milestones_url":"https://api.github.com/repos/ncalexan/datomish/milestones{/number}","notifications_url":"https://api.github.com/repos/ncalexan/datomish/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ncalexan/datomish/labels{/name}","releases_url":"https://api.github.com/repos/ncalexan/datomish/releases{/id}","deployments_url":"https://api.github.com/repos/ncalexan/datomish/deployments","created_at":"2016-07-05T22:48:01Z","updated_at":"2016-07-13T20:00:41Z","pushed_at":"2016-08-29T23:58:55Z","git_url":"git://github.com/ncalexan/datomish.git","ssh_url":"git@github.com:ncalexan/datomish.git","clone_url":"https://github.com/ncalexan/datomish.git","svn_url":"https://github.com/ncalexan/datomish","homepage":null,"size":279,"stargazers_count":1,"watchers_count":1,"language":"Clojure","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":3,"forks":0,"open_issues":3,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ncalexan/datomish/pulls/4"},"html":{"href":"https://github.com/ncalexan/datomish/pull/4"},"issue":{"href":"https://api.github.com/repos/ncalexan/datomish/issues/4"},"comments":{"href":"https://api.github.com/repos/ncalexan/datomish/issues/4/comments"},"review_comments":{"href":"https://api.github.com/repos/ncalexan/datomish/pulls/4/comments"},"review_comment":{"href":"https://api.github.com/repos/ncalexan/datomish/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ncalexan/datomish/pulls/4/commits"},"statuses":{"href":"https://api.github.com/repos/ncalexan/datomish/statuses/87a0a79d5ed6b451a7a3d57fbf0b37bfe53a720a"}}}}
{"actor":{"display_login":"ncalexan"}}