From 75fe19b26985f45050bb9dbdd3ee468984e8cb59 Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Sat, 3 Aug 2024 20:45:24 +0200 Subject: [PATCH] util:plist-equal (for tracking:save); work in progress: tracking:update; save: return track --- storage/tracking.lisp | 13 +++++-------- test/test-storage.lisp | 3 ++- util.lisp | 7 ++++++- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/storage/tracking.lisp b/storage/tracking.lisp index bb8696d..e02b60a 100644 --- a/storage/tracking.lisp +++ b/storage/tracking.lisp @@ -70,15 +70,11 @@ (found (query-last cont (shape:head-plist track)))) (if (null found) (insert track new-data) - (unless (plist-equal (shape:data found) new-data) + (unless (util:plist-equal (shape:data found) new-data) (if (eql force-insert :changed) (insert track new-data) (update track new-data)))))))) -(defun plist-equal (l1 l2) - (util:lgi l1 l2) - (equalp l1 l2)) - (defun insert (track &optional data) (ensure-timestamp track) (let* ((cont (container track)) @@ -96,9 +92,10 @@ (let* ((cont (container track)) (st (storage cont)) (table (storage:qualified-table-name st (table-name cont)))) - (sxql:update table - (apply #'sxql:make-clause ':set= (plist track data)) - (where (:= :trackid (trackid track)))))) + (storage:do-sql st + (sxql:update table + (apply #'sxql:make-clause ':set= (plist track data)) + (where (:= :trackid (trackid track))))))) ;;;; auxiliary functions for queries, ... diff --git a/test/test-storage.lisp b/test/test-storage.lisp index a97bfae..c52ef8f 100644 --- a/test/test-storage.lisp +++ b/test/test-storage.lisp @@ -74,6 +74,7 @@ (== (getf (shape:data pm2) :info) "test data") (setf pm3 (tracking:query-last cont '(:domain :test))) (util:lgi pm3) - ;(setf (getf (shape:data pm3) :info) "changed") + (msgstore:save pm3 cont) + (setf (getf (shape:data pm3) :info) "changed") (msgstore:save pm3 cont) )) diff --git a/util.lisp b/util.lisp index 391b807..1e9b797 100644 --- a/util.lisp +++ b/util.lisp @@ -3,7 +3,7 @@ (defpackage :scopes/util (:use :common-lisp) (:export #:lg #:lgd #:lgi - #:rtrim #:loop-plist #:plist-pairs + #:rtrim #:loop-plist #:plist-pairs #:plist-equal #:flatten-str #:to-keyword #:keyword-to-string #:to-string #:absolute-dir #:check-dir #:ensure-dir #:home-path #:path-from-string #:relative-path #:runtime-path #:system-path)) @@ -29,6 +29,11 @@ (defun plist-pairs (pl) (loop-plist pl k v collect (list k v))) +(defun plist-equal (l1 l2) + (loop-plist l1 k v do + (unless (equal (getf l2 k) v) + (return-from plist-equal nil))) + t) ;;;; strings, symbols, keywords, ... (defun flatten-str (s &key (sep " "))