From 5a75c10d746bb43d821c4951f6a28289adf50c4f Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Wed, 31 Jul 2024 16:51:04 +0200 Subject: [PATCH] tracking, msgstore: query-last basically working --- storage/tracking.lisp | 9 ++++++--- test/test-storage.lisp | 5 +++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/storage/tracking.lisp b/storage/tracking.lisp index 8535a49..0f50283 100644 --- a/storage/tracking.lisp +++ b/storage/tracking.lisp @@ -47,7 +47,7 @@ (make-instance (item-class cont) :head head :container cont)) (defun query-last (cont &rest head-specs) - (query-one cont (make-where head-specs) :order-by '(:timestamp :desc))) + (query-one cont (make-where head-specs) :order-by '((:desc :timestamp)))) (defun get-track (cont trid) (query-one cont (make-where (list (list :trackid trid))))) @@ -66,7 +66,8 @@ (insert track new-data) (update track new-data)))))) -(defun query-one (cont crit &key (order-by :trackid)) +(defun query-one (cont crit &key (order-by '(:trackid))) + ;(log:info "crit: ~s" crit) (let* ((tr (make-item cont)) (st (storage cont)) (table (storage:qualified-table-name st (table-name cont))) @@ -75,7 +76,7 @@ (sxql:select cols (sxql:from table) (sxql:where crit) - (sxql:order-by order-by) + (sxql:order-by (values-list order-by)) (sxql:limit 1))))))) (setup-track tr row))) @@ -111,6 +112,8 @@ (setf f :timestamp)) (unless op (setf op (if (eq f :timestamp) :>= :=))) + (when (symbolp v) + (setf v (string-downcase v))) (push (list op f v) crit)))) (if (cdr crit) (cons :and crit) diff --git a/test/test-storage.lisp b/test/test-storage.lisp index 778280e..a210294 100644 --- a/test/test-storage.lisp +++ b/test/test-storage.lisp @@ -61,7 +61,7 @@ (deftest test-msgstore (ctx) (let ((st (storage:storage ctx)) (data (make-hash-table)) - cont msg pm pm2) + cont msg pm pm2 pm3) (setf cont (msgstore:make-container st)) (storage:drop-table st :messages) (tracking:create-table cont) @@ -69,7 +69,8 @@ (setf pm (msgstore:save msg cont)) (== (tracking:trackid pm) 1) (setf pm2 (tracking:get-track cont 1)) - ;(log:info "pm2: ~s" pm2) (== (shape:head pm2) '(:test :data :field nil)) (== (getf (shape:data pm2) :info) "test data") + (setf pm3 (tracking:query-last cont '(:domain :test))) + (log:info "pm3: ~s" pm3) ))