branch: externals/gnosis
commit e3a3d27529bc6942134e9d0bc44ac25f2bfb1f06
Author: Thanos Apollo <[email protected]>
Commit: Thanos Apollo <[email protected]>

    [fix] replace gnosis-db with gnosis--ensure-db.
---
 gnosis-dashboard.el     |  6 +++---
 gnosis-export-import.el | 18 +++++++++---------
 gnosis-review.el        |  4 ++--
 gnosis.el               | 26 +++++++++++++-------------
 4 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/gnosis-dashboard.el b/gnosis-dashboard.el
index 9a47e199c9..aa0efb423b 100644
--- a/gnosis-dashboard.el
+++ b/gnosis-dashboard.el
@@ -395,7 +395,7 @@ Uses `gnosis-dashboard--entry-cache' to avoid re-querying 
known entries."
                    thema-ids)))
     ;; Fetch and cache only the missing entries
     (when uncached
-      (let ((rows (emacsql gnosis-db
+      (let ((rows (emacsql (gnosis--ensure-db)
                           `[:select
                             [themata:id themata:keimenon themata:hypothesis 
themata:answer
                                       themata:tags themata:type 
review-log:suspend]
@@ -491,7 +491,7 @@ Continues as long as the dashboard buffer exists."
                       ids))
            (new-warmed (+ warmed (length ids))))
       (when uncached
-        (let ((rows (emacsql gnosis-db
+        (let ((rows (emacsql (gnosis--ensure-db)
                      `[:select
                        [themata:id themata:keimenon themata:hypothesis 
themata:answer
                                    themata:tags themata:type 
review-log:suspend]
@@ -761,7 +761,7 @@ GEN: load generation — no-op if stale."
                           "Unsuspend all themata for tag? "
                         "Suspend all themata for tag?"))))
     (when confirm-msg
-      (emacsql gnosis-db
+      (emacsql (gnosis--ensure-db)
               `[:update review-log :set (= suspend ,suspend) :where
                         (in id ,(vconcat themata))])
       (if (= suspend 0)
diff --git a/gnosis-export-import.el b/gnosis-export-import.el
index e880439bbb..0af575ab87 100644
--- a/gnosis-export-import.el
+++ b/gnosis-export-import.el
@@ -181,13 +181,13 @@ When INCLUDE-SUSPENDED, also export suspended themata."
         (erase-buffer)
         (insert (format "#+DECK: %s\n" deck-name))
         ;; Batch-fetch: 2 queries instead of 2*N
-        (let* ((all-themata (emacsql gnosis-db
+        (let* ((all-themata (emacsql (gnosis--ensure-db)
                              [:select [id type keimenon hypothesis answer tags]
                               :from themata :where (= deck-id $s1)] deck))
                (all-ids (mapcar #'car all-themata))
                (suspended-ids (when (and all-ids (not include-suspended))
                                 (mapcar #'car
-                                        (emacsql gnosis-db
+                                        (emacsql (gnosis--ensure-db)
                                          [:select id :from review-log
                                           :where (and (in id $v1) (= suspend 
1))]
                                          (vconcat all-ids)))))
@@ -198,7 +198,7 @@ When INCLUDE-SUSPENDED, also export suspended themata."
                               all-themata))
                (all-ids (mapcar #'car all-themata))
                (all-extras (when all-ids
-                             (emacsql gnosis-db
+                             (emacsql (gnosis--ensure-db)
                               [:select [id parathema] :from extras
                                :where (in id $v1)] (vconcat all-ids))))
                (extras-ht (let ((ht (make-hash-table :test 'equal
@@ -257,13 +257,13 @@ When INCLUDE-SUSPENDED, also export suspended themata."
           (erase-buffer)
           (insert (format "#+DECK: %s\n" deck-name))
           ;; Batch-fetch: 2 queries instead of 2*N
-          (let* ((all-themata (emacsql gnosis-db
+          (let* ((all-themata (emacsql (gnosis--ensure-db)
                                [:select [id type keimenon hypothesis answer 
tags]
                                 :from themata :where (= deck-id $s1)] deck))
                  (all-ids (mapcar #'car all-themata))
                  (suspended-ids (when (and all-ids (not include-suspended))
                                   (mapcar #'car
-                                          (emacsql gnosis-db
+                                          (emacsql (gnosis--ensure-db)
                                            [:select id :from review-log
                                             :where (and (in id $v1) (= suspend 
1))]
                                            (vconcat all-ids)))))
@@ -274,7 +274,7 @@ When INCLUDE-SUSPENDED, also export suspended themata."
                                 all-themata))
                  (all-ids (mapcar #'car all-themata))
                  (all-extras (when all-ids
-                               (emacsql gnosis-db
+                               (emacsql (gnosis--ensure-db)
                                 [:select [id parathema] :from extras
                                  :where (in id $v1)] (vconcat all-ids))))
                  (extras-ht (let ((ht (make-hash-table :test 'equal
@@ -359,7 +359,7 @@ Returns nil on success, or an error message string on 
failure."
                               (puthash id t ht))))
         (errors nil)
         (edited-id (string-to-number (caar themata))))
-    (emacsql-with-transaction gnosis-db
+    (emacsql-with-transaction (gnosis--ensure-db)
       (cl-loop for thema in themata
               for err = (gnosis-save-thema thema deck)
               when err do (push err errors)))
@@ -391,7 +391,7 @@ before importing into it."
                             (dolist (id (gnosis-select 'id 'themata nil t) ht)
                               (puthash id t ht))))
         (errors nil))
-    (emacsql-with-transaction gnosis-db
+    (emacsql-with-transaction (gnosis--ensure-db)
       (cl-loop for thema in themata
               for err = (gnosis-save-thema thema deck)
               when err do (push err errors)))
@@ -446,7 +446,7 @@ Returns a list of error strings (nil on full success)."
       (insert header "\n" chunk)
       (org-mode)
       (let ((themata (gnosis-export-parse-themata)))
-        (emacsql-with-transaction gnosis-db
+        (emacsql-with-transaction (gnosis--ensure-db)
           (cl-loop for thema in themata
                    for err = (gnosis-save-thema thema deck-id)
                    when err do (push err errors)))))
diff --git a/gnosis-review.el b/gnosis-review.el
index 1bedc83585..304eabe145 100644
--- a/gnosis-review.el
+++ b/gnosis-review.el
@@ -319,7 +319,7 @@ SUCCESS is a boolean value, t for success, nil for failure."
         (t-fails (nth 4 log)))
     (gnosis-review-increment-activity-log (not (> n 0)))
     ;; Single review-log UPDATE
-    (emacsql gnosis-db
+    (emacsql (gnosis--ensure-db)
             "UPDATE review_log SET last_rev = $s1, next_rev = $s2, n = $s3, 
c_success = $s4, c_fails = $s5, t_success = $s6, t_fails = $s7 WHERE id = $s8"
             (gnosis-algorithm-date) next-rev (1+ n)
             (if success (1+ c-success) 0)
@@ -472,7 +472,7 @@ If NEW? is non-nil, increment new themata log by 1."
   "Delete all activity log entries."
   (interactive)
   (when (y-or-n-p "Delete all activity log?")
-    (emacsql gnosis-db [:delete :from activity-log])))
+    (emacsql (gnosis--ensure-db) [:delete :from activity-log])))
 
 ;;; Session management
 
diff --git a/gnosis.el b/gnosis.el
index 8f82e5c4fc..a470d291f9 100644
--- a/gnosis.el
+++ b/gnosis.el
@@ -343,7 +343,7 @@ Example:
 
 When VERIFICATION is non-nil, skip `y-or-n-p' prompt."
   (when (or verification (y-or-n-p "Delete thema?"))
-    (emacsql-with-transaction gnosis-db (gnosis--delete 'themata `(= id 
,id)))))
+    (emacsql-with-transaction (gnosis--ensure-db) (gnosis--delete 'themata `(= 
id ,id)))))
 
 (defun gnosis-delete-deck (&optional id)
   "Delete deck with ID."
@@ -351,7 +351,7 @@ When VERIFICATION is non-nil, skip `y-or-n-p' prompt."
   (let* ((id (or id (gnosis--get-deck-id)))
         (deck-name (gnosis--get-deck-name id)))
     (when (y-or-n-p (format "Delete deck `%s'? " deck-name))
-      (emacsql-with-transaction gnosis-db (gnosis--delete 'decks `(= id ,id)))
+      (emacsql-with-transaction (gnosis--ensure-db) (gnosis--delete 'decks `(= 
id ,id)))
       (message "Deleted deck `%s'" deck-name))))
 
 (defun gnosis-calculate-average-daily-reviews (&optional days)
@@ -604,7 +604,7 @@ When VERIFICATION is non-nil, skips `y-or-n-p' prompt."
                     (t (y-or-n-p
                         (format "Toggle suspend value for %s items? " 
items-num)))))))
     (when verification
-      (emacsql gnosis-db
+      (emacsql (gnosis--ensure-db)
                [:update review-log
                 :set (= suspend (- 1 suspend))
                 :where (in id $v1)]
@@ -621,7 +621,7 @@ When called with a prefix, unsuspends all themata in deck."
           (if (= suspend 0)
               "Unsuspend all themata for deck? " "Suspend all themata for 
deck? "))))
     (when confirm
-      (emacsql gnosis-db `[:update review-log :set (= suspend ,suspend) :where
+      (emacsql (gnosis--ensure-db) `[:update review-log :set (= suspend 
,suspend) :where
                                   (in id ,(vconcat themata))])
       (if (equal suspend 0)
          (message "Unsuspended %s themata" (length themata))
@@ -733,7 +733,7 @@ This function should be used in combination with
 (defun gnosis-get-tags--unique ()
   "Return a list of unique strings for tags in `gnosis-db'."
   (cl-loop for tags in (apply 'append
-                             (emacsql gnosis-db [:select :distinct tags :from 
themata]))
+                             (emacsql (gnosis--ensure-db) [:select :distinct 
tags :from themata]))
            nconc tags into all-tags
            finally return (delete-dups all-tags)))
 
@@ -799,7 +799,7 @@ DATE is a list of the form (year month day)."
 
 (defun gnosis-tags--update (tags)
   "Update db for TAGS."
-  (emacsql-with-transaction gnosis-db
+  (emacsql-with-transaction (gnosis--ensure-db)
     (cl-loop for tag in tags
             do (gnosis--insert-into 'tags `[,tag]))))
 
@@ -938,7 +938,7 @@ LINKS: List of id links."
   (cl-assert (listp links) nil "Links must be a list")
   (let* ((gnosis-id (or gnosis-id (gnosis-generate-id)))
         (review-image (or review-image "")))
-    (emacsql-with-transaction gnosis-db
+    (emacsql-with-transaction (gnosis--ensure-db)
       ;; Refer to `gnosis-db-schema-SCHEMA' e.g `gnosis-db-schema-review-log'
       (gnosis--insert-into 'themata `([,gnosis-id ,(downcase type) ,keimenon 
,hypothesis
                                              ,answer ,tags ,deck-id]))
@@ -1770,7 +1770,7 @@ Reopens the gnosis database after successful pull."
 
 (defun gnosis--update-themata-keimenon (updates)
   "Apply UPDATES list of (ID . NEW-KEIMENON) to database."
-  (emacsql-with-transaction gnosis-db
+  (emacsql-with-transaction (gnosis--ensure-db)
     (dolist (update updates)
       (gnosis-update 'themata `(= keimenon ,(cdr update)) `(= id ,(car 
update))))))
 
@@ -1898,23 +1898,23 @@ Fetches all themata, extras, and links in bulk queries."
 (defun gnosis--delete-orphaned-links (orphaned-dests)
   "Delete links whose dest is in ORPHANED-DESTS."
   (when orphaned-dests
-    (emacsql-with-transaction gnosis-db
-      (emacsql gnosis-db `[:delete :from links
+    (emacsql-with-transaction (gnosis--ensure-db)
+      (emacsql (gnosis--ensure-db) `[:delete :from links
                            :where (in dest ,(vconcat orphaned-dests))]))))
 
 (defun gnosis--delete-stale-links (stale-links)
   "Delete STALE-LINKS list of (source dest) from links table."
   (when stale-links
-    (emacsql-with-transaction gnosis-db
+    (emacsql-with-transaction (gnosis--ensure-db)
       (dolist (link stale-links)
-        (emacsql gnosis-db `[:delete :from links
+        (emacsql (gnosis--ensure-db) `[:delete :from links
                              :where (and (= source ,(car link))
                                          (= dest ,(cadr link)))])))))
 
 (defun gnosis--insert-missing-links (missing-links)
   "Insert MISSING-LINKS list of (source dest) into links table."
   (when missing-links
-    (emacsql-with-transaction gnosis-db
+    (emacsql-with-transaction (gnosis--ensure-db)
       (dolist (link missing-links)
         (gnosis--insert-into 'links `([,(car link) ,(cadr link)]))))))
 

Reply via email to