changeset 698: |
96958d3eb5b0 |
parent: |
97dd03beda03
|
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Fri, 04 Oct 2024 22:04:59 -0400 |
permissions: |
-rw-r--r-- |
description: |
fixes |
1 ;;; lib/obj/db/proto.lisp --- Database Protocol 13 (declaim (sb-kernel:type-specifier *default-database-type* *default-database-collection-type*)) 14 (defparameter *default-database-type* 'vector) 15 (defparameter *default-database-collection-type* 'list) 19 (:documentation "Return the Database associated with SELF.")) 22 ((db :initform nil :initarg :db :accessor db))) 24 (defclass database-collection () ()) 26 ;; TODO 2024-05-30: maybe make into a macro? 27 (defgeneric make-db (engine &rest initargs &key &allow-other-keys) 28 (:documentation "Dispatch initializer for databases. An ENGINE must be supplied, which is 29 usually a key such as :ROCKSDB or :SQLITE.")) 31 (defgeneric connect-db (db &key &allow-other-keys) 32 (:documentation "Connect the database DB.")) 34 (defgeneric query-db (db query &key &allow-other-keys) 35 (:documentation "Execute QUERY against DB.")) 37 (defgeneric db-get (db key &key &allow-other-keys) 38 (:documentation "Return the value associated with KEY from DB.")) 40 (defgeneric (setf db-get) (db key val &key &allow-other-keys)) 42 (defgeneric close-db (db &key &allow-other-keys) 43 (:documentation "Close the database DB.")) 45 (defgeneric open-db (self)) 47 (defgeneric destroy-db (self) 48 (:documentation "Destroy all traces of a database, deleting any on-disk data and shutting down 51 (defgeneric find-db (dbs name &key &allow-other-keys) 52 (:documentation "Return the db by NAME, from a collection of databases DBS.")) 54 (defgeneric insert-db (dbs name &key &allow-other-keys) 55 (:documentation "Inserts a database by NAME into the database-collection DBS.")) 57 (defgeneric db-open-p (self) 58 (:documentation "Return T when database SELF is open.") 59 (:method ((self t)) nil) 60 (:method ((self database)) (when (db self) t))) 62 (defgeneric db-closed-p (self) 63 (:documentation "Return T when database SELF is closed.") 64 (:method ((self t)) t) 65 (:method ((self database)) (unless (db self) t))) 68 (defun slot-val (instance slot-name) 70 (slot-boundp instance slot-name)) 71 (slot-value instance slot-name))) 73 (defgeneric get-val (object element &optional data-type) 74 (:documentation "Returns the value in a object based on the supplied element name and possible 76 (:method (object element &optional data-type) 78 (typecase (or data-type object) 80 (gethash element object)) 82 (slot-val object element)) 86 ((equal 'alist data-type) 87 (second (assoc element object :test #'equal))) 88 ((equal 'plist data-type) 91 (error "Does not handle this type of object. Implement your own get-val method."))) 93 (second (assoc element object :test #'equal)) 94 (error "Does not handle this type of object. Implement your own get-val method.")))))))) 97 (defgeneric (setf get-val) (new-value object element &optional data-type) 98 (:documentation "Set the value in a object based on the supplied element name and possible type 100 (:method (new-value object element &optional data-type) 101 (typecase (or data-type object) 102 (hash-table (setf (gethash element object) new-value)) 103 (standard-object (setf (slot-value object element) new-value)) 106 (cond ((equal 'alist data-type) 107 (replace object (list (list element new-value)))) 108 ((equal 'plist data-type) 109 ;;TODO: Implement this properly. 110 (get object element )) 112 (error "Does not handle this type of object. Implement your own get-val method."))) 114 (replace object (list (list element new-value))) 115 (error "Does not handle this type of object. Implement your own get-val method.")))))))