cl-scopes/storage/tracking.lisp

33 lines
912 B
Common Lisp

;;; cl-scopes/storage/tracking.lisp
;;;; A simple generic (SQL-based) storage for tracks, messages, and other stuff.
(defpackage :scopes/storage/tracking
(:use :common-lisp)
(:export #:track #:time-stamp #:data
#:container
#:create-table))
(in-package :scopes/storage/tracking)
(defclass track ()
((head)
(time-stamp :reader time-stamp :accessor time-stamp!)
(data :accessor data :initform nil)
(container :initarg :container)))
(defclass container ()
((storage :initarg :storage)))
(defun create-table (storage table-name head-fields)
storage
(let
((id-type 'bigserial)
(hf-def (mapcar #'(lambda (x) (list x :type 'text)) head-fields)))
(print (sxql:yield
(sxql:make-statement :create-table table-name
(nconc
`((trackid :type ,id-type :primary-key t))
hf-def
'((timestamp :type timestamp)
(data :type jsonb))))))))