Skip to content

Commit

Permalink
feat: switch to vulpea-db using extension capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
d12frosted committed Dec 10, 2022
1 parent 3473b0f commit 717dc22
Show file tree
Hide file tree
Showing 4 changed files with 214 additions and 356 deletions.
57 changes: 42 additions & 15 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,40 @@ This project started as a rewrite of [[https://github.com/d12frosted/environment
- [X] [[https://github.com/d12frosted/vino/milestone/1][v0.1]] - feature parity with [[https://github.com/d12frosted/environment/blob/3d387cb95353cfe79826d24abbfd1b6091669957/emacs/lisp/%2Borg-wine.el][+org-wine.el]].
- [X] [[https://github.com/d12frosted/vino/milestone/2][v0.2]] - dedicated database for =vino= needs.
- [X] v0.3 - migration to =org-roam= V2.
- [ ] [[https://github.com/d12frosted/vino/milestone/4][v0.4]] - querying and viewing.
- [ ] [[https://github.com/d12frosted/vino/milestone/3][v0.5]] - inventory solutions (built-in and external like [[https://github.com/d12frosted/environment/blob/0b5bc480758fd7ceeebc513317732f6337744126/emacs/lisp/lib-inventory.el][lib-inventory.el]]).
- [ ] v0.4 - migration to Vulpea database extension capabilities.
- [ ] [[https://github.com/d12frosted/vino/milestone/4][v0.5]] - querying and viewing.
- [ ] [[https://github.com/d12frosted/vino/milestone/3][v0.6]] - inventory solutions (built-in and external like [[https://github.com/d12frosted/environment/blob/0b5bc480758fd7ceeebc513317732f6337744126/emacs/lisp/lib-inventory.el][lib-inventory.el]]).

** Migration to v0.4
:PROPERTIES:
:ID: a702da58-6da9-48ca-9ca7-e2adab94c2a7
:END:

As part of [[https://github.com/d12frosted/vino/pull/121][vino#121]], =vino= stopped maintaining its own database and instead started to use Vulpea database extension mechanism that basically allows to extend Org Roam database. So all your =vino= data is now stored inside =org-orma-db-location=. This is a change that breaks API by removing some variables and functions.

The decision to use Vulpea database extension capabilities is dictated by desire to (a) reduce parsing duplication, (b) to align database lifecycle with vulpea and Org Roam, (c) to reduce code and (d) to get all Vulpea goodies related to database out of box (more to come).

*** Removed public variables
:PROPERTIES:
:ID: ef9d3858-c919-4bd5-b506-08e884683570
:END:

- =vino-db-location=, use =org-roam-db-location= instead.
- =vino-db-gc-threshold=, use =org-roam-db-gc-threshold= instead.

*** Removed public functions
:PROPERTIES:
:ID: f7dc613c-ee60-47bc-8117-8aa528143468
:END:

- =vino-db-sync=, use =org-roam-db-sync= instead.

*** Anything else?
:PROPERTIES:
:ID: e6b69c9b-b40c-46f6-bd38-21bee50ee13d
:END:

If you encounter troubles migrating to =v0.4=, feel free to open an issue.

** Getting started
:PROPERTIES:
Expand Down Expand Up @@ -78,7 +110,7 @@ Keep in mind that =vino= depends on [[https://github.com/d12frosted/vulpea][vulp
'(vino :type git :host github :repo "d12frosted/vino"))
(vino-setup)
;; optionally sync the database
(vino-db-sync)
(org-roam-db-sync)
#+end_src

In case you have [[https://github.com/raxod502/straight.el/#integration-with-use-package][integration]] with [[https://github.com/jwiegley/use-package][use-package]]:
Expand All @@ -93,7 +125,7 @@ In case you have [[https://github.com/raxod502/straight.el/#integration-with-use
(after-init . vino-setup)
:config
;; optionally sync the database when vino is loaded
(vino-db-sync))
(org-roam-db-sync))
#+end_src

*** Configuration
Expand All @@ -112,8 +144,6 @@ There are several things that you must configure before using =vino=:

Optionally you can configure the following variables:

- =vino-db-location= - the full path to file where =vino= database is stored.
- =vino-db-gc-threshold= - the temporary value for =gc-cons-threshold= to use during heavy operations like =vino-db-sync=. For performance considerations, you might set it to some high value (like =most-positive-fixnum=).
- =vino-carbonation-types= - list of carbonation types, e.g. =still= and =sparkling=. Modify it in case you want to be more granular, e.g. =traditional-sparkling=, =pet-nat=, etc.
- =vino-colour-types= - list of wine colours, e.g. =red=, =white= and =rose=. You might want to add =orange= unless you are marking them as =white=.
- =vino-sweetness-levels= - a property list where key is carbonation type and value is list of sweetness levels (e.g. =dry=, =sweet=, etc).
Expand Down Expand Up @@ -241,7 +271,6 @@ Optional variables (with their default values):
- =vino-region-create= - create a new =region= note according to =vino-region-template=.
- =vino-appellation-create= - create a new =appellation= note according to =vino-appellation-template=.
- =vino-region-find-file= - select and visit =region= or =appellation= note.
- =vino-db-sync= - build =vino= database cache.

** Notes structure
:PROPERTIES:
Expand Down Expand Up @@ -527,30 +556,28 @@ Files are tagged automatically by =vino= when entities are being created. You ca
:ID: a0a87902-0a63-47c0-88f5-179355819cdd
:END:

=vino= provides a dedicated database (just like =org-roam=) that can be used for fast querying of information. Right now there are no interactive uses for this database, they are planned in [[https://github.com/d12frosted/vino/milestone/3][v.0.3]] and [[https://github.com/d12frosted/vino/milestone/4][v0.4]]. But you already can build something on your own.
=vino= extends Org Roam database with tables that can be used for fast querying of information. Right now there are no interactive uses for this database, they are planned in [[https://github.com/d12frosted/vino/milestone/3][v0.6]] and [[https://github.com/d12frosted/vino/milestone/4][v0.5]]. But you already can build something on your own.

Available tables (see =vino-db--schemata= for full specification):
Available tables (see =vulpea-db--tables= for full specification):

- =cellar= - contains =vino-entry= (see *Vino entry*) with some technical metadata (=id=, =file= and =hash=);
- =ratings= - contains =vino-rating= (see *Vino rating*) with some technical metadata (=id=, =file= and =hash=).

In order to build database you need to manually call =vino-db-sync= (either from your =init.el= file after =vino-setup= or interactively).
In order to build database you need to manually call =org-roam-db-sync= (either from your =init.el= file after =vino-setup= or interactively).

If you properly installed =vino= (e.g. called =vino-setup=), then every time you modify and save a file, database will be automatically updated via =vino-db-update-file= function.
If you properly installed =vino= (e.g. called =vino-setup=), then every time you modify and save a file, database will be automatically updated.

In order to query information from database you might use =vino-db-query=:
In order to query information from database you might use =org-roam-db-query=:

#+begin_src emacs-lisp
;; query top rated wines with rating >= 9
(vino-db-query
(org-roam-db-query
[:select [producer name vintage rating]
:from cellar
:where (>= rating 9)
:order-by rating :desc])
#+end_src

Right now only low level =vino-db-query= is available, more functions will become available in [[https://github.com/d12frosted/vino/milestone/4][v0.4]].

** How to ...
:PROPERTIES:
:ID: c730ed42-0347-4778-b3fd-feab7f361db3
Expand Down
12 changes: 6 additions & 6 deletions test/utils/vino-test-utils.el
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,19 @@ a call to `save-match-data', as `format-spec' modifies that."
"Initialize testing environment in DIR."
(setq org-roam-directory dir
org-roam-db-location (expand-file-name "org-roam.db" dir)
vino-db-gc-threshold most-positive-fixnum)
(vulpea-db-autosync-enable)
(org-roam-db-autosync-enable)
vino-db-gc-threshold most-positive-fixnum
vino-rating-props '((1 . (("score" 20)))))
(vulpea-db-reset-tables)
(vino-setup)
(vino-db-sync))
(vulpea-db-autosync-enable)
(org-roam-db-autosync-enable))

(defun vino-test-teardown ()
"Teardown testing environment."
(vulpea-db-autosync-disable)
(org-roam-db-autosync-disable)
(delete-file org-roam-db-location)
(delete-file vino-db-location)
(vino-db--close))
(delete-file vino-db-location))



Expand Down
30 changes: 19 additions & 11 deletions test/vino-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,7 @@ dictum. Quisque suscipit neque dui, in efficitur quam interdum ut.
rating
note)
(before-each
(vino-test-init)
(setq vino-rating-props
'((1 . (("score" 20)))
(4 . (("property_1" 3)
Expand All @@ -938,8 +939,7 @@ dictum. Quisque suscipit neque dui, in efficitur quam interdum ut.
(list
:name "convive"
:mode 'multiple
:type 'string)))
(vino-test-init))
:type 'string))))

(after-each
(setq vino-rating-props nil
Expand Down Expand Up @@ -1130,7 +1130,7 @@ dictum. Quisque suscipit neque dui, in efficitur quam interdum ut.
date-str))))

(describe "vino-db"
(before-all
(before-each
(setq vino-rating-props
'((1 . (("score" 20)))
(4 . (("property_1" 3)
Expand All @@ -1140,16 +1140,10 @@ dictum. Quisque suscipit neque dui, in efficitur quam interdum ut.
("property_5" 6)))))
(vino-test-init))

(after-all
(after-each
(vino-test-teardown)
(setq vino-rating-props nil))

(it "subsequent call of vino-db-sync is fast when the cache is warm"
(let ((duration (benchmark-run 1
(vino-db-sync))))
(message "duration = %s" duration)
(expect (car duration) :to-be-less-than 1.0)))

(it "reading entries from file leads to the same result as reading from db"
(let* ((notes (vulpea-db-query #'vino-entry-note-p))
(ids (seq-map #'vulpea-note-id notes)))
Expand All @@ -1162,7 +1156,21 @@ dictum. Quisque suscipit neque dui, in efficitur quam interdum ut.
(ids (seq-map #'vulpea-note-id notes)))
(expect (seq-map #'vino-rating-get-by-id ids)
:to-equal
(seq-map #'vino-db-get-rating ids)))))
(seq-map #'vino-db-get-rating ids))))

(it "removing a cellar file removes it from database"
(let* ((id "c9937e3e-c83d-4d8d-a612-6110e6706252")
(note (vulpea-db-get-by-id id))
(file (vulpea-note-path note)))
(org-roam-db-clear-file file)
(expect (vino-db-get-rating id) :to-be nil)))

(it "removing a rating file removes it from database"
(let* ((id "f1ecb856-c009-4a65-a8d0-8191a9de66dd")
(note (vulpea-db-get-by-id id))
(file (vulpea-note-path note)))
(org-roam-db-clear-file file)
(expect (vino-db-get-rating id) :to-be nil))))

(describe "vino--collect-while"
(it "repeats a function until filter returns nil"
Expand Down
Loading

0 comments on commit 717dc22

Please sign in to comment.