[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/triples 6f8f3376f1 06/19: Add `triples-set-types'.
From: |
ELPA Syncer |
Subject: |
[elpa] externals/triples 6f8f3376f1 06/19: Add `triples-set-types'. |
Date: |
Sat, 5 Nov 2022 11:58:16 -0400 (EDT) |
branch: externals/triples
commit 6f8f3376f1e4df17a3113f88b41864556a25d7da
Author: Andrew Hyatt <ahyatt@gmail.com>
Commit: Andrew Hyatt <ahyatt@gmail.com>
Add `triples-set-types'.
This is an form useful for those who have many properties of different
types to
set all at once, replacing those types completely.
---
triples-test.el | 11 +++++++++++
triples.el | 16 ++++++++++++++++
2 files changed, 27 insertions(+)
diff --git a/triples-test.el b/triples-test.el
index f7e1b8f456..85a747966e 100644
--- a/triples-test.el
+++ b/triples-test.el
@@ -128,6 +128,17 @@ easily debug into it.")
(triples-delete-subject db "foo")
(should-not (triples-get-subject db "foo"))))
+(ert-deftest triples-set-types ()
+ (triples-test-with-temp-db
+ (triples-add-schema db 'named
+ '(name :unique t)
+ 'alias)
+ (triples-add-schema db 'reachable 'phone)
+ (triples-set-type db "foo" 'named :name "Name" :alias '("alias1" "alias2"))
+ (triples-set-types db "foo" :named/name "New Name" :reachable/phone
'("867-5309"))
+ (should (equal (triples-test-plist-sort '(:named/name "New Name"
:reachable/phone ("867-5309")))
+ (triples-test-plist-sort (triples-get-subject db "foo"))))))
+
(ert-deftest triples-single-element ()
(triples-test-with-temp-db
(triples-add-schema db 'named 'name)
diff --git a/triples.el b/triples.el
index 149d13cd63..c825bf0000 100644
--- a/triples.el
+++ b/triples.el
@@ -168,6 +168,22 @@ PROPERTIES is a plist of properties, without TYPE
prefixes."
(triples-verify-schema-compliant db (cdr op))
(triples--add db op)))
+(defun triples-set-types (db subject &rest combined-props)
+ "Set all data for types in COMBINED-PROPS in DB for SUBJECT.
+COMBINED-PROPS is a plist which takes combined properties such as
+:named/name and their values. All other data related to the types
+given in the COMBINED-PROPS will be removed."
+ (let ((type-to-plist (make-hash-table)))
+ (triples--plist-mapc
+ (lambda (cp val)
+ (pcase-let ((`(,type . ,prop) (triples-combined-to-type-and-prop cp)))
+ (puthash (triples--decolon type)
+ (plist-put (gethash (triples--decolon type) type-to-plist)
+ (triples--encolon prop) val) type-to-plist)))
+ combined-props)
+ (cl-loop for k being the hash-keys of type-to-plist using (hash-values v)
+ do (apply #'triples-set-type db subject k v))))
+
(defun triples--set-type-op (subject type properties)
"Create operation to replace PROPERTIES for TYPE for SUBJECT.
PROPERTIES is a plist of properties, without TYPE prefixes."
- [elpa] branch externals/triples created (now d17b3d6e17), ELPA Syncer, 2022/11/05
- [elpa] externals/triples 7d5aca3bb8 02/19: Fix issue where single element lists were not being treated as lists., ELPA Syncer, 2022/11/05
- [elpa] externals/triples 6f8f3376f1 06/19: Add `triples-set-types'.,
ELPA Syncer <=
- [elpa] externals/triples 5e8abd2989 01/19: Initial commit of triples module., ELPA Syncer, 2022/11/05
- [elpa] externals/triples cc5629fe5c 07/19: Wrap all database access in `triples-set-types' in a transaction., ELPA Syncer, 2022/11/05
- [elpa] externals/triples 257de87fdc 08/19: Minor code cleanup., ELPA Syncer, 2022/11/05
- [elpa] externals/triples 4627d6ed6d 10/19: Fix minor mistakes in ert tests., ELPA Syncer, 2022/11/05
- [elpa] externals/triples fb63dfe44a 12/19: Convert to sqlite., ELPA Syncer, 2022/11/05
- [elpa] externals/triples 0252dad7d1 17/19: Fixes from code review from Stefan Monnier., ELPA Syncer, 2022/11/05
- [elpa] externals/triples d17b3d6e17 19/19: Merge branch 'combined'., ELPA Syncer, 2022/11/05
- [elpa] externals/triples 2dae3d49b9 18/19: Various fixes for emacsql code, which wasn't being tested correctly., ELPA Syncer, 2022/11/05
- [elpa] externals/triples 6afcb290ca 15/19: Support both emacs 29 sqlite and emacsql., ELPA Syncer, 2022/11/05
- [elpa] externals/triples aca95ba7f3 03/19: Ensure that we don't duplicate triples., ELPA Syncer, 2022/11/05