branch: externals/org-gnosis
commit 9a6921d3c44e86b7d94d74608213c7e6534c6811
Author: Thanos Apollo <pub...@thanosapollo.org>
Commit: Thanos Apollo <pub...@thanosapollo.org>

    [fix] Make sure database is initialized.
    
    * I've been assuming users would run org-gnosis-db-sync first thing
      after installing org-gnosis.
    
    * This change adjusts for new users that might have not already have a
      collection of notes from org-roam to import & would just start
      calling org-gnosis-find or org-gnosis-insert immediately.
---
 org-gnosis.el | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/org-gnosis.el b/org-gnosis.el
index 905a4caafd..e8e5575b24 100644
--- a/org-gnosis.el
+++ b/org-gnosis.el
@@ -89,6 +89,7 @@
   "Select VALUE from TABLE, optionally with RESTRICTIONS.
 
 Optional argument FLATTEN, when non-nil, flattens the result."
+  (org-gnosis-db-init-if-needed)
   (let ((output (emacsql org-gnosis-db
                         `[:select ,value :from ,table :where ,restrictions])))
     (if flatten
@@ -725,5 +726,13 @@ If called with ARG do not initialize the database."
        (emacsql org-gnosis-db [:create-table $i1 $S2] table schema))
       (emacsql org-gnosis-db [:pragma (= user-version 
org-gnosis-db-version)]))))
 
+(defun org-gnosis-db-init-if-needed ()
+  "Init database if it has not been initizalized."
+  (when (length< (emacsql org-gnosis-db
+                         [:select name :from sqlite-master :where (= type 
table)])
+                4)
+    (message "Creating org-gnosis database...")
+    (org-gnosis-db-init)))
+
 (provide 'org-gnosis)
 ;;; org-gnosis.el ends here

Reply via email to