storage/tracking: data is always a plist - convert internally on save or retrieve

This commit is contained in:
Helmut Merz 2024-07-28 19:39:16 +02:00
parent 484b3251d1
commit 69c3013332
2 changed files with 10 additions and 9 deletions

View file

@ -47,7 +47,10 @@
(with-slots ((trid trackid) (ts time-stamp) (data shape:data)) track
(if trid (setf (getf vl :trackid) trid))
(if ts (setf (getf vl :timestamp) (timestamp-to-sql track ts)))
(if data (setf (getf vl :data) (jzon:stringify data))))
(when data
(unless (hash-table-p data)
(setf data (alx:plist-hash-table data)))
(setf (getf vl :data) (jzon:stringify data))))
vl))
(defun insert (track)
@ -81,7 +84,8 @@
(setf (trackid tr) (getf row :trackid))
(setf (time-stamp tr) (getf row :timestamp))
(setf (shape:data tr)
(jzon:parse (getf row :data) :key-fn #'util:to-keyword))
(alx:hash-table-plist
(jzon:parse (getf row :data) :key-fn #'util:to-keyword)))
tr))
(defun create-table (cont)

View file

@ -42,7 +42,6 @@
(deftest test-track (ctx)
(let ((st (storage:storage ctx))
(data (make-hash-table))
cont tr tr2)
(setf cont (make-instance 'tracking:container :storage st))
(storage:drop-table st :tracks)
@ -51,13 +50,12 @@
(== (shape:head tr) '(:t01 :john))
(== (shape:head-plist tr) '(:username "john" :taskid "t01"))
(== (shape:data tr) nil)
(setf (gethash :desc data) "scopes/storage: queries")
(setf (shape:data tr) data)
(setf (shape:data tr) '(:desc "scopes/storage: queries"))
(tracking:insert tr)
(== (tracking:trackid tr) 1)
(setf tr2 (tracking:get-track cont 1))
(== (shape:head tr2) '(:t01 :john))
(== (gethash :desc (shape:data tr2)) "scopes/storage: queries")
(== (getf (shape:data tr2) :desc) "scopes/storage: queries")
))
(deftest test-msglog (ctx)
@ -67,12 +65,11 @@
(setf cont (msglog:make-container st))
(storage:drop-table st :messages)
(tracking:create-table cont)
(setf msg (message:create '(:test :data :field)
:data (alx:plist-hash-table '(:info "test data"))))
(setf msg (message:create '(:test :data :field) :data '(:info "test data")))
(setf pm (msglog: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))
(== (gethash :info (shape:data pm2)) "test data")
(== (getf (shape:data pm2) :info) "test data")
))