tracking, msgstore: query-last basically working

This commit is contained in:
Helmut Merz 2024-07-31 16:51:04 +02:00
parent 97a86d6154
commit 5a75c10d74
2 changed files with 9 additions and 5 deletions

View file

@ -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)

View file

@ -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)
))