Commit 06338d08 authored by ryszard.szopa's avatar ryszard.szopa
Browse files

redefinition of db-class and db-class-slot-definition


 * FOREIGN: whether there should be a foreign key constraint with the
column representing this slot

 * UNIQUE: whether there should be a unique constraint for this key

 * ON-DELETE: action to be taken on deletion of the referenced
row. Relevant only if foreign is T.

 * DELAYED-CONSTRAINT: place to store a closure adding a foreign key
constraint if it is not possible to add it now (when the referenced
table doesn't yet exist

New slots in DB-CLASS:

 * FOREIGN-KEYS list of slots that are foreign keys

 * UNFINISHED-CLASSES: class allocated. Instances for which there are
constraints that should be applied.

parent c3b21e2a
......@@ -16,13 +16,33 @@ ignored in all database related operations.")
(not-null :initform nil :initarg :not-null :accessor not-null-p
:documentation "If non-NIL, a NON NULL database
constrained will be introduced.")
(foreign :initform nil :initarg :foreign :accessor foreign-type-p)))
(foreign :initform nil :initarg :foreign :accessor foreign-type-p)
(unique :initform nil :initarg :unique :accessor unique)
(on-delete :initform :cascade :initarg :on-delete :accessor on-delete
:documentation "Action to be performed for this slot
when the refering row in the database ceases to exist. Possible
values: :CASCADE, :RESTRICT, :SET-NULL, :SET-DEFAULT. If this slot is
not a foreign key, it does nothing.")
(delayed-constraint :initform nil :accessor delayed-constraint
:documentation "Closures adding constraints
that, for some reason, could not be executed. If there's a slot with
this attribute not-NIL in a class definition, then there's something
wrong with its SQL counterpart.")))
(defmetaclass db-class (standard-class)
((indices :initarg :indices :initform () :reader db-class-indices)
;; TODO: Additional slot, CONSTRAINTS.
(connection-spec :initarg :connection-spec :initform nil :reader db-class-connection-spec))
(connection-spec :initarg :connection-spec :initform nil :reader db-class-connection-spec)
(unfinished-classes :initform nil :allocation :class :accessor db-class-unfinished-classes
:documentation "A class allocated slot
containing classes for whom not all the constraints could be
(foreign-keys :initform nil :accessor db-class-foreign-keys
:documentation "List of foreign-key slots.")
(unique-keys :initform nil :accessor db-class-unique-keys
:documentation "List of slots whose value should be unique."))
(:documentation "Metaclass for PostgreSQL aware classes. It takes
two additional arguments in DEFTABLE: :INDICES (which slots are used
as indices) and :CONNECTION-SPEC, which specifies how the class should
......@@ -48,6 +68,7 @@ metaclass set to DB-CLASS."
(setf (transient-p slotd) (every #'transient-p direct-slot-definitions))
(setf (foreign-type-p slotd) (foreign-type-p (car direct-slot-definitions)))
(setf (not-null-p slotd) (not-null-p (car direct-slot-definitions)))
(setf (unique slotd) (unique (car direct-slot-definitions)))
;; (defgeneric foreign-type-p (slot)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment