Skip to content

Commit

Permalink
feat: vulpea-db-query-by-tags-none
Browse files Browse the repository at this point in the history
  • Loading branch information
d12frosted committed Nov 13, 2023
1 parent 8f3ea45 commit e1ea848
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.org
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Handle forced database sync. Whenever it happens, make sure that all the extra tables are initialized and versions are set accordingly.
- Respect aliases used in the meta blocks when extracting value as a note.
- Introduce =vulpea-insert-default-candidates-source=.
- Introduce =vulpea-db-query-by-tags-none=.

** v0.3.0
:PROPERTIES:
Expand Down
2 changes: 2 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,7 @@ As you can see, =vulpea-db-query= doesn't allow to pass any custom SQL for filte

- =vulpea-db-query-by-tags-some= - return all notes tagged with one of the provided =TAGS=.
- =vulpea-db-query-by-tags-every= - return all notes tagged by every tag from the list of provided =TAGS=.
- =vulpea-db-query-by-tags-none= - return all notes not tagged by any tag from the list of provided =TAGS=.
- =vulpea-db-query-by-links-some= - return all notes linking at least one of the provided =DESTINATIONS=.
- =vulpea-db-query-by-links-every= - return all notes linking each and every provided =DESTINATIONS=.

Expand Down Expand Up @@ -1330,6 +1331,7 @@ This library provides multiple functions to query notes from the database. Basic

- =vulpea-db-query-by-tags-some= - return all notes tagged with one of the provided =TAGS=.
- =vulpea-db-query-by-tags-every= - return all notes tagged by every tag from the list of provided =TAGS=.
- =vulpea-db-query-by-tags-none= - return all notes not tagged by any tag from the list of provided =TAGS=.
- =vulpea-db-query-by-links-some= - return all notes linking at least one of the provided =DESTINATIONS=.
- =vulpea-db-query-by-links-every= - return all notes linking each and every provided =DESTINATIONS=.

Expand Down
20 changes: 20 additions & 0 deletions test/vulpea-db-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,26 @@
(seq-contains-p note-tags tag))
tags)))))))))

(describe "vulpea-db-query-by-tags-none"
(before-all
(vulpea-test--init))

(after-all
(vulpea-test--teardown))

(it "acts as vulpea-db-query when no tags are provided"
(expect (seq-length (vulpea-db-query-by-tags-none nil))
:to-equal
(seq-length (vulpea-db-query))))

(it "returns the same elements as vulpea-db-query"
(expect
(vulpea-db-query-by-tags-none '("tag2" "tag3"))
:to-have-same-items-as
(vulpea-db-query
(lambda (note)
(not (vulpea-note-tagged-any-p note "tag2" "tag3")))))))

(describe "vulpea-db-query-by-links-some"
(before-all
(vulpea-test--init))
Expand Down
17 changes: 17 additions & 0 deletions vulpea-db.el
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,23 @@ TAGS are returned."
tags)
"\nintersect\n"))))))

(defun vulpea-db-query-by-tags-none (tags)
"Query a list of `vulpea-note' from database.
Only notes that are NOT tagged by any tag from the list of TAGS
are returned."
(emacsql-with-transaction (org-roam-db)
(vulpea-db-query-by-ids
(seq-map
#'car
(org-roam-db-query
[:select :distinct [id]
:from nodes
:where id :not :in [:select :distinct [node_id]
:from tags
:where tag :in $v1]]
(apply #'vector tags))))))

(defun vulpea-db-query-by-links-some (destinations)
"Query a list of `vulpea-note' from database.
Expand Down

0 comments on commit e1ea848

Please sign in to comment.