summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2024-03-08 08:21:11 +0200
committerThanos Apollo <[email protected]>2024-03-08 08:33:09 +0200
commit27a5c3fec34f97d9cf1189a848acaf5b2f2d35c1 (patch)
tree1a54264d1dcf33b6b919e61dacfba05eeabf2767
parent51fb1c37af5fe1cda46883d7ce983bc49bab255a (diff)
gnosis-add-note-fields: Refactor using emacsql-with-transaction
-rw-r--r--gnosis.el17
1 files changed, 8 insertions, 9 deletions
diff --git a/gnosis.el b/gnosis.el
index 8901782..0072b3a 100644
--- a/gnosis.el
+++ b/gnosis.el
@@ -500,15 +500,14 @@ SECOND-IMAGE: Image to display after user-input.
NOTE: If a gnosis--insert-into fails, the whole transaction will be
(or at least it should). Else there will be an error for foreign key
constraint."
- (condition-case nil
- (progn
- ;; Refer to `gnosis-db-schema-SCHEMA' e.g `gnosis-db-schema-review-log'
- (gnosis--insert-into 'notes `([nil ,type ,main ,options ,answer ,tags ,(gnosis--get-deck-id deck)]))
- (gnosis--insert-into 'review `([nil ,gnosis-algorithm-ef ,gnosis-algorithm-ff ,gnosis-algorithm-interval]))
- (gnosis--insert-into 'review-log `([nil ,(gnosis-algorithm-date) ,(gnosis-algorithm-date) 0 0 0 0 ,suspend 0]))
- (gnosis--insert-into 'extras `([nil ,extra ,image ,second-image])))
- (error (message "An error occurred during insertion"))))
-
+ (let* ((deck-id (gnosis--get-deck-id deck))
+ (initial-interval (gnosis-get-deck-initial-interval deck-id)))
+ (emacsql-with-transaction gnosis-db
+ ;; Refer to `gnosis-db-schema-SCHEMA' e.g `gnosis-db-schema-review-log'
+ (gnosis--insert-into 'notes `([nil ,type ,main ,options ,answer ,tags ,deck-id]))
+ (gnosis--insert-into 'review `([nil ,gnosis-algorithm-ef ,gnosis-algorithm-ff ,initial-interval]))
+ (gnosis--insert-into 'review-log `([nil ,(gnosis-algorithm-date) ,(gnosis-algorithm-date) 0 0 0 0 ,suspend 0]))
+ (gnosis--insert-into 'extras `([nil ,extra ,image ,second-image])))))
;; Adding note(s) consists firstly of a hidden 'gnosis-add-note--TYPE'
;; function that does the computation & error checking to generate a