branch: externals/triples
commit f991abd5502e85a7717bb8b75cd6ed3ac6157db1
Merge: e24233b65b a324f9054f
Author: Andrew Hyatt <[email protected]>
Commit: Andrew Hyatt <[email protected]>

    Merge branch 'main' into develop
---
 NEWS.org                | 21 +++++++++++++++++++++
 triples-backups-test.el |  3 +++
 triples-backups.el      | 14 ++++++++++----
 triples.el              | 49 +++++++++++++++++++++++++++----------------------
 4 files changed, 61 insertions(+), 26 deletions(-)

diff --git a/NEWS.org b/NEWS.org
new file mode 100644
index 0000000000..6bcdfa5d34
--- /dev/null
+++ b/NEWS.org
@@ -0,0 +1,21 @@
+TITLE: Changelog for the triples module for GNU Emacs.
+
+* 0.2.4
+- Move the =CHANGELOG.org= file to =NEWS.org= so the changes show up in GNU 
ELPA.
+* 0.2.3
+- Allow =nil= for =filename= arguments in the backup functions.  This will 
default to backing up the default database.
+- Fix issue with fallback for bad backup strategies.
+* 0.2.2
+- Fix error behavior using Emacs builtin sqlite.  Now error is rethrown 
instead of swallowed.
+* 0.2.1
+- Add backup strategy =never=.
+* 0.2
+- Create a default database to encourage a shared triple database.  Add 
information on why this is an interesting idea in the README.
+- Add support for backups of databases via =triples-backup=, and a simple way 
to have a sane and shared backups created with the new =triples-backups= module.
+- Add =triples-move-subject= which will move both a subject as well as 
reference to it.
+* 0.1.2
+- Bugfix release to remove backward compatibility with pre-Emacs 29 versions.  
+* 0.1.1
+ - Bugfix release to fix =triples-subject-with-predicate-object=.
+* 0.1
+- This is the initial version that contained basic triple functionality, and 
was integrated into GNU ELPA.
diff --git a/triples-backups-test.el b/triples-backups-test.el
index c1f9dd2491..5885d32530 100644
--- a/triples-backups-test.el
+++ b/triples-backups-test.el
@@ -60,6 +60,9 @@
       (should-not backup-called)
       (triples-backups-setup db 3 'always)
       (triples-backups-maybe-backup db filename)
+      (should backup-called)
+      (triples-backups-setup db 3 'unknown)
+      (triples-backups-maybe-backup db filename)
       (should backup-called))))
 
 (provide 'triples-backups-test)
diff --git a/triples-backups.el b/triples-backups.el
index 631f87b5d1..28299fb42e 100644
--- a/triples-backups.el
+++ b/triples-backups.el
@@ -48,9 +48,11 @@ If no one has ever run that on this database, `nil' is 
returned."
   "Get the last time DB has been updated."
   (plist-get (triples-get-type db 'database 'backup) :last-update-time))
 
-(defun triples-backups-maybe-backup (db filename)
+(defun triples-backups-maybe-backup (db &optional filename)
   "If it is time for DB to be backed up, then back it up.
-FILENAME is also necessary for the backup operation."
+FILENAME is optional, as in `triples-connect', if not given will
+default to the standard triple database given in
+`triples-default-database-filename'."
   (let* ((backup-info (triples-backups-configuration db))
          (strategy-func (intern (format "triples-backups-strategy-%s"
                                         (plist-get backup-info :strategy)))))
@@ -62,8 +64,8 @@ FILENAME is also necessary for the backup operation."
        (format "Triples backup strategy %s not found, defaulting to 
`triples-backups-strategy-daily'" 
                strategy-func)
        :error))
-    (when (funcall (or (symbol-function strategy-func) 
triples-backups-strategy-daily)
-                 (time-convert (plist-get backup-info :last-update-time) t))
+    (when (funcall (or (symbol-function strategy-func) 
#'triples-backups-strategy-daily)
+                   (time-convert (plist-get backup-info :last-update-time) t))
       (triples-backup db filename (plist-get backup-info :num-to-keep))
       (apply #'triples-set-type db 'database 'backup (plist-put backup-info 
:last-update-time (time-convert (current-time) 'integer))))))
 
@@ -71,6 +73,10 @@ FILENAME is also necessary for the backup operation."
   "Backup strategy to do a backup on each change."
   t)
 
+(defun triples-backups-strategy-never (_)
+  "Backup strategy to never do a backup."
+  nil)
+
 (defun triples-backups-strategy-daily (last-update)
   "Backup strategy to create a change daily at most.
 LAST-UPDATE is the time of the last update."
diff --git a/triples.el b/triples.el
index 9f252ff44a..83a7d98294 100644
--- a/triples.el
+++ b/triples.el
@@ -1,12 +1,12 @@
-;;; triples.el --- A flexible triple-based database for us in apps.  -*- 
lexical-binding: t; -*-
+;;; triples.el --- A flexible triple-based database for use in apps  -*- 
lexical-binding: t; -*-
 
 ;; Copyright (c) 2022  Free Software Foundation, Inc.
 
 ;; Author: Andrew Hyatt <[email protected]>
 ;; Homepage: https://github.com/ahyatt/triples
-;; Package-Requires: ((seq "2.0") (emacs "25"))
+;; Package-Requires: ((seq "2.0") (emacs "28.1"))
 ;; Keywords: triples, kg, data, sqlite
-;; Version: 0.2
+;; Version: 0.2.3
 ;; This program is free software; you can redistribute it and/or
 ;; modify it under the terms of the GNU General Public License as
 ;; published by the Free Software Foundation; either version 2 of the
@@ -105,17 +105,21 @@ work, therefore this function must be called instead.
 Th DB argument is currently unused, but may be used in the future
 if emacs's native sqlite gains a backup feature.
 
+FILENAME can be nil, if so `triples-default-database-filename'
+will be used.
+
 This also will clear excess backup files, according to
 NUM-TO-KEEP, which specifies how many backup files at max should
 exist at any time. Older backups are the ones that are deleted."
-  (call-process (pcase triples-sqlite-interface
-                  ('builtin triples-sqlite-executable)
-                  ('emacsql emacsql-sqlite-executable))
-                nil nil nil (expand-file-name filename)
-                (format ".backup '%s'" (expand-file-name
-                                        (car (find-backup-file-name
-                                              (expand-file-name filename))))))
-  (let ((backup-files (file-backup-file-names (expand-file-name filename))))
+  (let ((filename (expand-file-name (or filename 
triples-default-database-filename))))
+    (call-process (pcase triples-sqlite-interface
+                    ('builtin triples-sqlite-executable)
+                    ('emacsql emacsql-sqlite-executable))
+                  nil nil nil filename
+                  (format ".backup '%s'" (expand-file-name
+                                          (car (find-backup-file-name
+                                                filename))))))
+  (let ((backup-files (file-backup-file-names filename)))
     (cl-loop for backup-file in (cl-subseq
                                  backup-files
                                  (min num-to-keep (length backup-files)))
@@ -162,7 +166,7 @@ with PROPERTIES. This is a low-level function that bypasses 
our
 normal schema checks, so should not be called from client programs."
   (unless (symbolp predicate)
     (error "Predicates in triples must always be symbols"))
-  (unless (plistp properties)
+  (when (and (fboundp 'plistp) (not (plistp properties)))
     (error "Properties stored must always be plists"))
   (pcase triples-sqlite-interface
     ('builtin 
@@ -441,16 +445,17 @@ The transaction will abort if an error is thrown."
 
 (defun triples--with-transaction (db body-fun)
   (pcase triples-sqlite-interface
-    ('builtin  (condition-case nil
-                   (progn
-                     (sqlite-transaction db)
-                     (funcall body-fun)
-                     (sqlite-commit db))
-                 (error (sqlite-rollback db))))
-    ('emacsql (funcall (triples--eval-when-fboundp emacsql-with-transaction
-                         (lambda (db body-fun)
-                           (emacsql-with-transaction db (funcall body-fun))))
-                       db body-fun))))
+      ('builtin  (condition-case err
+                     (progn
+                       (sqlite-transaction db)
+                       (funcall body-fun)
+                       (sqlite-commit db))
+                   (error (sqlite-rollback db)
+                          (signal (car err) (cdr err)))))
+      ('emacsql (funcall (triples--eval-when-fboundp emacsql-with-transaction
+                           (lambda (db body-fun)
+                             (emacsql-with-transaction db (funcall body-fun))))
+                         db body-fun))))
 
 (defun triples-set-types (db subject &rest combined-props)
   "Set all data for types in COMBINED-PROPS in DB for SUBJECT.

Reply via email to