{"action":"created","comment":{"url":"https://api.github.com/repos/jarun/Buku/pulls/comments/68488752","id":68488752,"diff_hunk":"@@ -614,32 +615,82 @@ class BukuDb:\n         if debug:\n             print(\"\\\"%s\\\", (%s)\" % (query, arguments))\n \n-        self.cur.execute(query, arguments)\n-        results = self.cur.fetchall()\n-        if len(results) == 0:\n-            return\n+        # if it's search & delete, ask for confirmation, but only once\n+        ask = delete\n \n-        if not json:\n-            prompt(results, self.noninteractive)\n-        else:\n-            print(format_json(results))\n+        while True:\n+            self.cur.execute(query, arguments)\n+            results = self.cur.fetchall()\n+            # no matches found\n+            if len(results) == 0:\n+                return\n+\n+            if not json:\n+                if delete is False:\n+                    # just search and open results if wanted\n+                    prompt(results, self.noninteractive)\n+                    return\n+                # time to delete, now..\n+                if ask is True:\n+                    # first iteration, just print the results and ask for confirmation\n+                    count = 0\n+                    for row in results:\n+                        count += 1\n+                        print_record(row, count)\n+                    resp = input('Delete search results? Enter \\x1b[1my\\x1b[21m to confirm: ')\n+                    if resp != 'y' and resp != 'Y':\n+                        return\n+                    # the results have been printed, let's delete them one by one\n+                    ask = False\n+                    continue\n+                else:\n+                    # delete the records now (no confirmation)\n+                    # db will be compacted after each delete, so delete the first item and search again\n+                    bdb.delete_bookmark(int(results[0][0]))\n+            else:\n+                print(format_json(results))\n \n-    def search_by_tag(self, tag, json=False):\n+    def search_by_tag(self, tag, json=False, delete=False):\n         \"\"\"Search and list bookmarks with a tag\n \n         :param tag: tag to search\n         :param json: print in json format\n+        :param delete: delete search results\n         \"\"\"\n \n-        self.cur.execute(\"SELECT id, url, metadata, tags, desc FROM bookmarks WHERE tags LIKE '%' || ? || '%'\", (tag,))\n-        results = self.cur.fetchall()\n-        if len(results) == 0:\n-            return\n+        # if it's search & delete, ask for confirmation, but only once\n+        ask = delete\n \n-        if not json:\n-            prompt(results, self.noninteractive)\n-        else:\n-            print(format_json(results))\n+        while True:\n+            self.cur.execute(\"SELECT id, url, metadata, tags, desc FROM bookmarks WHERE tags LIKE '%' || ? || '%'\", (tag,))","path":"buku","position":84,"original_position":84,"commit_id":"29571843dbb79473388a8c4c0e178b0e1885ed19","original_commit_id":"29571843dbb79473388a8c4c0e178b0e1885ed19","user":{"login":"jarun","id":5959286,"avatar_url":"https://avatars.githubusercontent.com/u/5959286?v=3","gravatar_id":"","url":"https://api.github.com/users/jarun","html_url":"https://github.com/jarun","followers_url":"https://api.github.com/users/jarun/followers","following_url":"https://api.github.com/users/jarun/following{/other_user}","gists_url":"https://api.github.com/users/jarun/gists{/gist_id}","starred_url":"https://api.github.com/users/jarun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jarun/subscriptions","organizations_url":"https://api.github.com/users/jarun/orgs","repos_url":"https://api.github.com/users/jarun/repos","events_url":"https://api.github.com/users/jarun/events{/privacy}","received_events_url":"https://api.github.com/users/jarun/received_events","type":"User","site_admin":false},"body":"We can do this using a single query instead of querying again and again. One query returns all matching indices. The while loop in 664 should go after line 674.","created_at":"2016-06-25T13:42:04Z","updated_at":"2016-06-25T13:42:04Z","html_url":"https://github.com/jarun/Buku/pull/49#discussion_r68488752","pull_request_url":"https://api.github.com/repos/jarun/Buku/pulls/49","_links":{"self":{"href":"https://api.github.com/repos/jarun/Buku/pulls/comments/68488752"},"html":{"href":"https://github.com/jarun/Buku/pull/49#discussion_r68488752"},"pull_request":{"href":"https://api.github.com/repos/jarun/Buku/pulls/49"}}},"pull_request":{"url":"https://api.github.com/repos/jarun/Buku/pulls/49","id":75204621,"html_url":"https://github.com/jarun/Buku/pull/49","diff_url":"https://github.com/jarun/Buku/pull/49.diff","patch_url":"https://github.com/jarun/Buku/pull/49.patch","issue_url":"https://api.github.com/repos/jarun/Buku/issues/49","number":49,"state":"open","locked":false,"title":"Add batch-delete feature","user":{"login":"dstuxo","id":144200,"avatar_url":"https://avatars.githubusercontent.com/u/144200?v=3","gravatar_id":"","url":"https://api.github.com/users/dstuxo","html_url":"https://github.com/dstuxo","followers_url":"https://api.github.com/users/dstuxo/followers","following_url":"https://api.github.com/users/dstuxo/following{/other_user}","gists_url":"https://api.github.com/users/dstuxo/gists{/gist_id}","starred_url":"https://api.github.com/users/dstuxo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dstuxo/subscriptions","organizations_url":"https://api.github.com/users/dstuxo/orgs","repos_url":"https://api.github.com/users/dstuxo/repos","events_url":"https://api.github.com/users/dstuxo/events{/privacy}","received_events_url":"https://api.github.com/users/dstuxo/received_events","type":"User","site_admin":false},"body":"When any search flag (-s/-S/--st) is combined with\r\n-d, the results can be deleted","created_at":"2016-06-25T13:23:31Z","updated_at":"2016-06-25T13:42:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"76bb3b82f612134d6714cd2b57cec359d543f348","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/jarun/Buku/pulls/49/commits","review_comments_url":"https://api.github.com/repos/jarun/Buku/pulls/49/comments","review_comment_url":"https://api.github.com/repos/jarun/Buku/pulls/comments{/number}","comments_url":"https://api.github.com/repos/jarun/Buku/issues/49/comments","statuses_url":"https://api.github.com/repos/jarun/Buku/statuses/29571843dbb79473388a8c4c0e178b0e1885ed19","head":{"label":"dstuxo:batch_delete","ref":"batch_delete","sha":"29571843dbb79473388a8c4c0e178b0e1885ed19","user":{"login":"dstuxo","id":144200,"avatar_url":"https://avatars.githubusercontent.com/u/144200?v=3","gravatar_id":"","url":"https://api.github.com/users/dstuxo","html_url":"https://github.com/dstuxo","followers_url":"https://api.github.com/users/dstuxo/followers","following_url":"https://api.github.com/users/dstuxo/following{/other_user}","gists_url":"https://api.github.com/users/dstuxo/gists{/gist_id}","starred_url":"https://api.github.com/users/dstuxo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dstuxo/subscriptions","organizations_url":"https://api.github.com/users/dstuxo/orgs","repos_url":"https://api.github.com/users/dstuxo/repos","events_url":"https://api.github.com/users/dstuxo/events{/privacy}","received_events_url":"https://api.github.com/users/dstuxo/received_events","type":"User","site_admin":false},"repo":{"id":61943791,"name":"Buku","full_name":"dstuxo/Buku","owner":{"login":"dstuxo","id":144200,"avatar_url":"https://avatars.githubusercontent.com/u/144200?v=3","gravatar_id":"","url":"https://api.github.com/users/dstuxo","html_url":"https://github.com/dstuxo","followers_url":"https://api.github.com/users/dstuxo/followers","following_url":"https://api.github.com/users/dstuxo/following{/other_user}","gists_url":"https://api.github.com/users/dstuxo/gists{/gist_id}","starred_url":"https://api.github.com/users/dstuxo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dstuxo/subscriptions","organizations_url":"https://api.github.com/users/dstuxo/orgs","repos_url":"https://api.github.com/users/dstuxo/repos","events_url":"https://api.github.com/users/dstuxo/events{/privacy}","received_events_url":"https://api.github.com/users/dstuxo/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dstuxo/Buku","description":"Powerful command-line bookmark manager. Your mini web!","fork":true,"url":"https://api.github.com/repos/dstuxo/Buku","forks_url":"https://api.github.com/repos/dstuxo/Buku/forks","keys_url":"https://api.github.com/repos/dstuxo/Buku/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dstuxo/Buku/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dstuxo/Buku/teams","hooks_url":"https://api.github.com/repos/dstuxo/Buku/hooks","issue_events_url":"https://api.github.com/repos/dstuxo/Buku/issues/events{/number}","events_url":"https://api.github.com/repos/dstuxo/Buku/events","assignees_url":"https://api.github.com/repos/dstuxo/Buku/assignees{/user}","branches_url":"https://api.github.com/repos/dstuxo/Buku/branches{/branch}","tags_url":"https://api.github.com/repos/dstuxo/Buku/tags","blobs_url":"https://api.github.com/repos/dstuxo/Buku/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dstuxo/Buku/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dstuxo/Buku/git/refs{/sha}","trees_url":"https://api.github.com/repos/dstuxo/Buku/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dstuxo/Buku/statuses/{sha}","languages_url":"https://api.github.com/repos/dstuxo/Buku/languages","stargazers_url":"https://api.github.com/repos/dstuxo/Buku/stargazers","contributors_url":"https://api.github.com/repos/dstuxo/Buku/contributors","subscribers_url":"https://api.github.com/repos/dstuxo/Buku/subscribers","subscription_url":"https://api.github.com/repos/dstuxo/Buku/subscription","commits_url":"https://api.github.com/repos/dstuxo/Buku/commits{/sha}","git_commits_url":"https://api.github.com/repos/dstuxo/Buku/git/commits{/sha}","comments_url":"https://api.github.com/repos/dstuxo/Buku/comments{/number}","issue_comment_url":"https://api.github.com/repos/dstuxo/Buku/issues/comments{/number}","contents_url":"https://api.github.com/repos/dstuxo/Buku/contents/{+path}","compare_url":"https://api.github.com/repos/dstuxo/Buku/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dstuxo/Buku/merges","archive_url":"https://api.github.com/repos/dstuxo/Buku/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dstuxo/Buku/downloads","issues_url":"https://api.github.com/repos/dstuxo/Buku/issues{/number}","pulls_url":"https://api.github.com/repos/dstuxo/Buku/pulls{/number}","milestones_url":"https://api.github.com/repos/dstuxo/Buku/milestones{/number}","notifications_url":"https://api.github.com/repos/dstuxo/Buku/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dstuxo/Buku/labels{/name}","releases_url":"https://api.github.com/repos/dstuxo/Buku/releases{/id}","deployments_url":"https://api.github.com/repos/dstuxo/Buku/deployments","created_at":"2016-06-25T13:11:25Z","updated_at":"2016-06-25T13:11:26Z","pushed_at":"2016-06-25T13:21:16Z","git_url":"git://github.com/dstuxo/Buku.git","ssh_url":"git@github.com:dstuxo/Buku.git","clone_url":"https://github.com/dstuxo/Buku.git","svn_url":"https://github.com/dstuxo/Buku","homepage":"","size":1132,"stargazers_count":0,"watchers_count":0,"language":"Python","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":"jarun:master","ref":"master","sha":"0b7cc736a37db248e6b102cb15102b1c81dc3de8","user":{"login":"jarun","id":5959286,"avatar_url":"https://avatars.githubusercontent.com/u/5959286?v=3","gravatar_id":"","url":"https://api.github.com/users/jarun","html_url":"https://github.com/jarun","followers_url":"https://api.github.com/users/jarun/followers","following_url":"https://api.github.com/users/jarun/following{/other_user}","gists_url":"https://api.github.com/users/jarun/gists{/gist_id}","starred_url":"https://api.github.com/users/jarun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jarun/subscriptions","organizations_url":"https://api.github.com/users/jarun/orgs","repos_url":"https://api.github.com/users/jarun/repos","events_url":"https://api.github.com/users/jarun/events{/privacy}","received_events_url":"https://api.github.com/users/jarun/received_events","type":"User","site_admin":false},"repo":{"id":45355064,"name":"Buku","full_name":"jarun/Buku","owner":{"login":"jarun","id":5959286,"avatar_url":"https://avatars.githubusercontent.com/u/5959286?v=3","gravatar_id":"","url":"https://api.github.com/users/jarun","html_url":"https://github.com/jarun","followers_url":"https://api.github.com/users/jarun/followers","following_url":"https://api.github.com/users/jarun/following{/other_user}","gists_url":"https://api.github.com/users/jarun/gists{/gist_id}","starred_url":"https://api.github.com/users/jarun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jarun/subscriptions","organizations_url":"https://api.github.com/users/jarun/orgs","repos_url":"https://api.github.com/users/jarun/repos","events_url":"https://api.github.com/users/jarun/events{/privacy}","received_events_url":"https://api.github.com/users/jarun/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jarun/Buku","description":"Powerful command-line bookmark manager. Your mini web!","fork":false,"url":"https://api.github.com/repos/jarun/Buku","forks_url":"https://api.github.com/repos/jarun/Buku/forks","keys_url":"https://api.github.com/repos/jarun/Buku/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jarun/Buku/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jarun/Buku/teams","hooks_url":"https://api.github.com/repos/jarun/Buku/hooks","issue_events_url":"https://api.github.com/repos/jarun/Buku/issues/events{/number}","events_url":"https://api.github.com/repos/jarun/Buku/events","assignees_url":"https://api.github.com/repos/jarun/Buku/assignees{/user}","branches_url":"https://api.github.com/repos/jarun/Buku/branches{/branch}","tags_url":"https://api.github.com/repos/jarun/Buku/tags","blobs_url":"https://api.github.com/repos/jarun/Buku/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jarun/Buku/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jarun/Buku/git/refs{/sha}","trees_url":"https://api.github.com/repos/jarun/Buku/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jarun/Buku/statuses/{sha}","languages_url":"https://api.github.com/repos/jarun/Buku/languages","stargazers_url":"https://api.github.com/repos/jarun/Buku/stargazers","contributors_url":"https://api.github.com/repos/jarun/Buku/contributors","subscribers_url":"https://api.github.com/repos/jarun/Buku/subscribers","subscription_url":"https://api.github.com/repos/jarun/Buku/subscription","commits_url":"https://api.github.com/repos/jarun/Buku/commits{/sha}","git_commits_url":"https://api.github.com/repos/jarun/Buku/git/commits{/sha}","comments_url":"https://api.github.com/repos/jarun/Buku/comments{/number}","issue_comment_url":"https://api.github.com/repos/jarun/Buku/issues/comments{/number}","contents_url":"https://api.github.com/repos/jarun/Buku/contents/{+path}","compare_url":"https://api.github.com/repos/jarun/Buku/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jarun/Buku/merges","archive_url":"https://api.github.com/repos/jarun/Buku/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jarun/Buku/downloads","issues_url":"https://api.github.com/repos/jarun/Buku/issues{/number}","pulls_url":"https://api.github.com/repos/jarun/Buku/pulls{/number}","milestones_url":"https://api.github.com/repos/jarun/Buku/milestones{/number}","notifications_url":"https://api.github.com/repos/jarun/Buku/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jarun/Buku/labels{/name}","releases_url":"https://api.github.com/repos/jarun/Buku/releases{/id}","deployments_url":"https://api.github.com/repos/jarun/Buku/deployments","created_at":"2015-11-01T19:53:18Z","updated_at":"2016-06-25T11:50:25Z","pushed_at":"2016-06-25T13:23:32Z","git_url":"git://github.com/jarun/Buku.git","ssh_url":"git@github.com:jarun/Buku.git","clone_url":"https://github.com/jarun/Buku.git","svn_url":"https://github.com/jarun/Buku","homepage":"","size":1132,"stargazers_count":364,"watchers_count":364,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":26,"mirror_url":null,"open_issues_count":3,"forks":26,"open_issues":3,"watchers":364,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/jarun/Buku/pulls/49"},"html":{"href":"https://github.com/jarun/Buku/pull/49"},"issue":{"href":"https://api.github.com/repos/jarun/Buku/issues/49"},"comments":{"href":"https://api.github.com/repos/jarun/Buku/issues/49/comments"},"review_comments":{"href":"https://api.github.com/repos/jarun/Buku/pulls/49/comments"},"review_comment":{"href":"https://api.github.com/repos/jarun/Buku/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/jarun/Buku/pulls/49/commits"},"statuses":{"href":"https://api.github.com/repos/jarun/Buku/statuses/29571843dbb79473388a8c4c0e178b0e1885ed19"}}}}
{"actor":{"display_login":"jarun"}}