From 15531cf283e70b970b0468ee2a35f72eefd7ebfa Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Tue, 28 Nov 2023 15:23:21 +0200 Subject: Add gnosis-db Add gnosis-db at user-emacs-directory --- gnosis.el | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'gnosis.el') diff --git a/gnosis.el b/gnosis.el index 64fc46a..2e42d9c 100644 --- a/gnosis.el +++ b/gnosis.el @@ -36,32 +36,31 @@ (require 'cl-lib) (require 'animate) +(defvar gnosis-db (emacsql-sqlite (concat user-emacs-directory "gnosis.db"))) + (cl-defun gnosis--select (table values &optional (restrictions '1=1)) "Select VALUES from TABLE, optionally with RESTRICTIONS." - (emacsql-with-connection (db (emacsql-sqlite "test2.db")) - (emacsql db `[:select ,values :from ,table :where ,restrictions]))) + (emacsql gnosis-db `[:select ,values :from ,table :where ,restrictions])) (cl-defun gnosis--create-table (table-name &optional values) "Create TABLE-NAME for VALUES." - (emacsql-with-connection (db (emacsql-sqlite "test2.db")) - (emacsql db `[:create-table ,table-name ,values]))) + (emacsql gnosis-db `[:create-table ,table-name ,values])) (cl-defun gnosis--insert-into (table-name values) "Insert VALUES to TABLE-NAME." - (emacsql-with-connection (db (emacsql-sqlite "test2.db")) - (emacsql db `[:insert :into ,table-name :values ,values]))) + (emacsql gnosis-db `[:insert :into ,table-name :values ,values])) (defun gnosis--get-question (id) "Get question row for question ID." - (caar (gnosis--select 'gnosis1 'question `(= question_id ,id)))) + (caar (gnosis--select 'notes 'question `(= question_id ,id)))) (defun gnosis--get-correct-answer (id) "Get correct answer for question ID." - (caar (gnosis--select 'gnosis1 'answer `(= question_id ,id)))) + (caar (gnosis--select 'notes 'answer `(= question_id ,id)))) (defun gnosis--get-mcanswers (id) "Get multiple choices for question ID." - (caar (gnosis--select 'gnosis1 'mchoices `(= question_id ,id)))) + (caar (gnosis--select 'notes 'choices `(= question_id ,id)))) (defun gnosis--display-question (id) "Display question for question ID." -- cgit v1.2.3