Commit b7097b02 authored by ryszard.szopa's avatar ryszard.szopa
Browse files

not-null slot in db-class-slot introduced.

darcs-hash:f54037b3229d1901d7f5dee7c05551759cfb0187
parent 49fdedee
......@@ -27,8 +27,11 @@ names is used."))
(format nil "~A~{_~A~}_index" (to-sql-name class-name) (mapcar #'to-sql-name fields)))
(type-and-reference (slot)
(if (foreign-type-p slot)
(list :type 'integer :references (list (list (slot-definition-type slot) 'id) :cascade)) ;is this cascade ok?
`(:type ,(slot-definition-type slot)))))
(list :type (if (not-null-p slot) 'integer '(or db-null integer))
:references (list (list (slot-definition-type slot) 'id) :cascade)) ;is this cascade ok?
(list :type (if (not-null-p slot)
(slot-definition-type slot)
`(or db-null ,(slot-definition-type slot)))))))
(postmodern:execute
(sql-compile
`(:create-table ,class-name
......
......@@ -34,7 +34,10 @@ metaclass set to DB-CLASS."
((transient :initform nil :initarg :transient :accessor transient-p
:documentation
"If non-NIL, this slot should be treated as transient and
ignored in all database related operations.")))
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.")))
......@@ -58,7 +61,11 @@ ignored in all database related operations.")))
(defgeneric foreign-type-p (slot)
(:documentation "Is SLOT foreign?")
(:method ((slot db-class-slot-definition))
(typep (find-class (slot-definition-type slot)) 'db-class)))
(let ((s-d-t (slot-definition-type slot)))
(if (listp s-d-t)
(error "Slots whose type is defined by a list commencing
with 'OR, 'NOT, or 'AND are not supported by DB-CLASS.")
(typep (find-class s-d-t) 'db-class)))))
(defmethod direct-slot-definition-class ((class db-class) &rest initargs)
(declare (ignore initargs))
......
Markdown is supported
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