Coverage report: /home/ellis/comp/core/app/skel/core/db.lisp

KindCoveredAll%
expression3175 41.3
branch12 50.0
Key
Not instrumented
Conditionalized out
Executed
Not executed
 
Both branches taken
One branch taken
Neither branch taken
1
 ;;; db.lisp --- Skel Database Protocol
2
 
3
 ;; 
4
 
5
 ;;; Code:
6
 (in-package :skel/core/db)
7
 
8
 (load-database-backend :rdb)
9
 
10
 (defvar *skel-db-path* (merge-homedir-pathnames ".stash/skel/db/"))
11
 (defun skel-db-path (path) (merge-pathnames path *skel-db-path*))
12
 
13
 (defun skel-db-spec (path &optional (backend :rdb))
14
   "Return a list which can be safely stored in the SPEC slot of a STORE."
15
   (list backend (directory-path (skel-db-path path))))
16
 
17
 (defvar *default-skel-db-spec* (skel-db-spec "default"))
18
 
19
 (defclass skel-db (rdb-database) 
20
   ()
21
   (:default-initargs
22
    :db (make-db :rocksdb :name "skel-db" :opts (default-rdb-opts))))
23
 
24
 (defmethod make-db ((engine (eql :skel)) &rest initargs &key name path &allow-other-keys)
25
   (let ((name (or name (when path (namestring path)))))
26
     (remf initargs :name)
27
     (remf initargs :path)
28
     (let ((db (apply 'make-instance 'skel-db initargs)))
29
       (when name (setf (name db) name))
30
       db)))
31
 
32
 (defaccessor name ((self skel-db)) (rdb-name (db self)))
33
 (defaccessor path ((self skel-db)) (rdb-name (db self)))
34
 
35
 (defmethod initialize-instance :before ((self skel-db) &rest initargs &key name path &allow-other-keys)
36
   (declare (ignore initargs))
37
   (unless name
38
     (unless (not path)
39
       (setf name (namestring path)))))
40
 
41
 (defmethod start :after ((self skel-db))
42
   (setq *db* (open-db self)))
43
 
44
 (defclass skel-store (store) ()
45
   (:default-initargs :spec *default-skel-db-spec*))
46
 
47
 (defmethod start :after ((self skel-store))
48
   (setq *store* self))
49
 
50
 (defclass skel-db-schema (upgradable-schema)
51
   ((collection :type (vector rdb-schema) :initarg :collection :accessor schema-collection))
52
   (:default-initargs
53
    :name "skel-db"))
54
 
55
 (defclass skel-object-schema (object-schema) ())
56
 
57
 (defclass skel-record (id) ()
58
   (:metaclass stored-class))
59
 
60
 (defvar *skel-registry-db* (make-db :skel :path (skel-db-path "registry") :schema *skel-registry-schema*))
61
 (defvar *skel-cache-db* (make-db :skel :path (skel-db-path "cache") :schema *skel-cache-schema*))
62
 ;; (with-db (db :db *skel-cache-db* :open t :close t))