Add remove-tags command

This command removes the given tags (or all if none are specified) from
a bookmark's tag list.
This commit is contained in:
Tom Willemse 2013-07-02 22:30:46 +02:00
parent 6121891396
commit df47a68535
4 changed files with 29 additions and 4 deletions

View file

@ -158,6 +158,11 @@ Replace @var{url}'s tags with @var{tags}. @var{tags} may be omitted,
in which case all the tags for @var{url} are removed. in which case all the tags for @var{url} are removed.
@end deffn @end deffn
@deffn Command remove-tags URL [TAGS...]
Remove @var{tags} from @var{url}'s tag list. If @var{tags} is omitted,
remove all tags from @var{url}'s tag list.
@end deffn
@node Miscellaneous, , Management, Usage @node Miscellaneous, , Management, Usage
@section Other things that can be done @section Other things that can be done

View file

@ -36,5 +36,5 @@ $(install-binaries): install-%: %
$(uninstall-binaries): uninstall-%: $(uninstall-binaries): uninstall-%:
rm -f "$(DESTDIR)/bin/$*" rm -f "$(DESTDIR)/bin/$*"
clark: clark.lisp make-image.lisp clark: clark.lisp queries.lisp make-image.lisp
$(LISP) --load make-image.lisp $(LISP) --load make-image.lisp

View file

@ -285,6 +285,14 @@ Get a random bookmark. If TAG is given limit the result to a bookmark
having the tag TAG." having the tag TAG."
(format t "~a~%" (random-item (url-list tag)))) (format t "~a~%" (random-item (url-list tag))))
(defcommand remove-tags (url &rest tags)
"Remove given tags from bookmark's tag list."
"Usage: clark remove-tags <url> [<tags> ...]
Remove the given TAGS from URL's tag list. If no tags are given,
remove all tags from bookmark."
(delete-tags url tags))
(defcommand version () (defcommand version ()
"Show version." "Show version."
"Usage: clark version "Usage: clark version

View file

@ -68,10 +68,22 @@
(execute-non-query (execute-non-query
*db* (sql delete from "bookmark" where "url" = ?) url)) *db* (sql delete from "bookmark" where "url" = ?) url))
(defun delete-tags (id) (defun delete-tags (id &optional tags)
"Clear the tags for bookmark with id ID." "Clear the tags for bookmark with id ID."
(execute-non-query *db* (sql delete from "bookmark_tag" (if tags
where "bookmark_id" = ?) id)) (map nil
(lambda (tag)
(execute-non-query
*db* (sql delete from "bookmark_tag"
where "bookmark_id" = (select "rowid"
from "bookmark"
where "url" = ?)
and "tag_id" in (select "rowid"
from "tag"
where "name" = ?))
id tag)) tags)
(execute-non-query *db* (sql delete from "bookmark_tag"
where "bookmark_id" = ?) id)))
(defun get-bookmark-id (url) (defun get-bookmark-id (url)
"Get the id of the bookmark for URL." "Get the id of the bookmark for URL."