38 lines
1.1 KiB
Common Lisp
38 lines
1.1 KiB
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)
|
|
(:local-nicknames (:storage :scopes/storage))
|
|
(: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 (st table-name head-fields)
|
|
(let*
|
|
((params (storage:db-params st))
|
|
(id-type (getf params :id-type))
|
|
(json-type (getf params :json-type))
|
|
(hf-def (mapcar #'(lambda (x) (list x :type 'text)) head-fields))
|
|
(sql
|
|
(sxql:yield
|
|
(sxql:make-statement :create-table table-name
|
|
(nconc
|
|
`((trackid :type ,id-type :primary-key t))
|
|
hf-def
|
|
`((timestamp :type timestamp)
|
|
(data :type ,json-type)))))))
|
|
(print sql)
|
|
(dbi:do-sql (storage:db st) sql)))
|