54 lines
1.6 KiB
Common Lisp
54 lines
1.6 KiB
Common Lisp
;;;; cl-scopes/storage/folder - persistent folders, stored in a SQL database.
|
|
|
|
(defpackage :scopes/storage/folder
|
|
(:use :common-lisp)
|
|
(:local-nicknames (:shape :scopes/shape)
|
|
(:tracking :scopes/storage/tracking)
|
|
(:util :scopes/util))
|
|
(:export #:folder #:root #:create #:items #:parent
|
|
#:make-container))
|
|
|
|
(in-package :scopes/storage/folder)
|
|
|
|
(defclass folder (tracking:track)
|
|
((shape:meta :initform
|
|
(make-instance 'shape:record-meta
|
|
:head-fields '(:parentid :name :ref))
|
|
:allocation :class)
|
|
(tracking:key-fields :initform '(:parentid :name))))
|
|
|
|
(defun indexes (cont)
|
|
'((parentid name) (ref)))
|
|
|
|
(defun make-container (storage)
|
|
(make-instance 'tracking:container
|
|
:item-class 'folder
|
|
:short-name :fldr
|
|
:table-name :folders
|
|
:index-factory #'indexes
|
|
:force-insert-when nil
|
|
:storage storage))
|
|
|
|
(defun root (cont)
|
|
(tracking:save (tracking:make-item cont nil :root)))
|
|
|
|
(defun create (name parent)
|
|
(let ((cont (tracking:container parent))
|
|
(pid (tracking:id-str parent)))
|
|
(tracking:save (tracking:make-item cont pid name))))
|
|
|
|
(defun items (f)
|
|
(query f `((:parentid ,(id f)))))
|
|
|
|
(defun parent (f)
|
|
(let ((pid (util:to-integer (shape:head-value f :parentid))))
|
|
(tracking:query-one (tracking:container f)
|
|
(tracking:make-where `((:trackid ,pid))))))
|
|
|
|
;;;; auxiliary functions
|
|
|
|
(defun id (f)
|
|
(tracking:id-str f))
|
|
|
|
(defun query (f spec)
|
|
(tracking:query (tracking:container f) (tracking:make-where spec)))
|