create table: use container settings for table name and head fields
This commit is contained in:
parent
49688e4055
commit
9e1a8a92b9
2 changed files with 12 additions and 6 deletions
|
@ -18,11 +18,16 @@
|
||||||
(container :initarg :container)))
|
(container :initarg :container)))
|
||||||
|
|
||||||
(defclass container ()
|
(defclass container ()
|
||||||
((storage :initarg :storage)))
|
((storage :initarg :storage)
|
||||||
|
(table-name :reader table-name :initform :tracks)
|
||||||
|
(head-fields :reader head-fields :initform '(:taskid :username))
|
||||||
|
(indexes :reader indexes :initform '((:taskid :username) (username)))))
|
||||||
|
|
||||||
(defun create-table (st table-name head-fields)
|
(defun create-table (st cont)
|
||||||
(let*
|
(let*
|
||||||
((params (storage:db-params st))
|
((table-name (table-name cont))
|
||||||
|
(head-fields (head-fields cont))
|
||||||
|
(params (storage:db-params st))
|
||||||
(id-type (getf params :id-type))
|
(id-type (getf params :id-type))
|
||||||
(json-type (getf params :json-type))
|
(json-type (getf params :json-type))
|
||||||
(hf-def (mapcar #'(lambda (x)
|
(hf-def (mapcar #'(lambda (x)
|
||||||
|
@ -34,7 +39,7 @@
|
||||||
`((trackid :type ,id-type :primary-key t :not-null t))
|
`((trackid :type ,id-type :primary-key t :not-null t))
|
||||||
hf-def
|
hf-def
|
||||||
`((timestamp :type timestamptz :not-null t :default current_timestamp)
|
`((timestamp :type timestamptz :not-null t :default current_timestamp)
|
||||||
(data :type ,json-type)))))))
|
(data :type ,json-type :not-null t :default |'{}'|)))))))
|
||||||
|
|
||||||
(defun create-indexes (st tname ixs)
|
(defun create-indexes (st tname ixs)
|
||||||
(let ((i 1)
|
(let ((i 1)
|
||||||
|
|
|
@ -37,8 +37,9 @@
|
||||||
(t:show-result)))
|
(t:show-result)))
|
||||||
|
|
||||||
(defun test-track (st)
|
(defun test-track (st)
|
||||||
(let ((tr (make-instance 'tracking:track)))
|
(let* ((cont (make-instance 'tracking:container))
|
||||||
|
(tr (make-instance 'tracking:track :container cont)))
|
||||||
(storage:drop-table st :tracks)
|
(storage:drop-table st :tracks)
|
||||||
(tracking:create-table st :tracks '(taskid username))
|
(tracking:create-table st cont)
|
||||||
(tracking:create-indexes st :tracks '((taskid) (taskid username)))
|
(tracking:create-indexes st :tracks '((taskid) (taskid username)))
|
||||||
(== (tracking:data tr) nil)))
|
(== (tracking:data tr) nil)))
|
||||||
|
|
Loading…
Add table
Reference in a new issue