X-Git-Url: https://git.hcoop.net/clinton/lisp-on-lines.git/blobdiff_plain/579597e310dfac262d629aade17f86c3d6b80da4..e9454185bda3d35420ad39ae2817260bd222e789:/src/meta-model.lisp diff --git a/src/meta-model.lisp b/src/meta-model.lisp index b0d1ff5..2fbe4b5 100644 --- a/src/meta-model.lisp +++ b/src/meta-model.lisp @@ -16,7 +16,8 @@ :initform nil) (base-type :accessor meta-model.base-type - :initform 'clsql))) + :initarg :base-type + :initform :clsql))) (defmethod meta-model.metadata ((self (eql nil))) nil) @@ -31,36 +32,32 @@ (cons 'meta-model-class supers)))) (defmethod %def-meta-model ((base-type t) name supers slots &rest options) - `(defclass ,name ,(gen-supers supers) - () - (:default-initargs :metadata ',slots))) + `(eval-when (:compile-toplevel :load-toplevel :execute) + (defclass ,name ,(gen-supers supers) + () + (:default-initargs :metadata ',slots :base-type ,base-type)))) (defmacro def-meta-model (name supers slots &rest options) - `(progn + `(eval-when (:compile-toplevel :load-toplevel :execute) (when (not (member (quote ,name) *meta-models*)) (setf *meta-models* (cons (quote ,name) *meta-models*))) (let ((class ,(%def-meta-model (cadr (or (assoc :base-type options) '(t t))) name supers slots options))) class))) -(defgeneric def-base-class-expander (model base-type name args)) +(defgeneric def-base-type-class-expander (base-type model name args)) - -(defmacro def-base-class (name (model) &rest args) - (let ((i (make-instance model))) - `(progn - ,(def-base-class-expander i :clsql name args) - (defmethod meta-model.metadata ((m ,name)) - ',(meta-model.metadata i))))) - +(defmethod def-base-class-expander ((model t) name args) + (def-base-type-class-expander (meta-model.base-type model) model name args)) (defmethod base-class-name ((model t)) (class-name (class-of (meta-model.instance model)))) - - (defmethod view-class-metadata ((model t)) + " +This is what meta-model.metadata used to be called, +most of the below functions expect this method to exist" (meta-model.metadata model)) (defun list-item-helper (type view &key (ret-fun #'car)) @@ -160,7 +157,10 @@ "returns the clsql view-class joined on SLOT" (dolist (s (list-join-attributes model)) (when (equal (getf (cdr s) :home-key) slot) - (return-from explode-foreign-key (slot-value model (car s)))))) + (let ((val (slot-value model (car s)))) + (return-from explode-foreign-key + (values (if val val (make-instance (getf (cdr s) :join-class))) + (getf (cdr s) :foreign-key))))))) (defun find-join-helper (foreign-key) (lambda (class slot) @@ -175,5 +175,52 @@ "returns the SLOT in the foreign VIEW-CLASS that joins with FOREIGN-KEY" (car (list-relations-helper view (find-join-helper foreign-key) :return-key :foreign-key))) +(defmethod explode-has-many ((view t) join-slot) + "returns the class of the join as the primary value, the second and third value is the home key and the foreign key" + (let ((att (assoc join-slot (list-join-attributes view)))) + (values (getf (cdr att) :join-class) + (getf (cdr att) :home-key) + (getf (cdr att) :foreign-key)))) + +(defgeneric expr-= (instance slot-name value) + (:documentation "Create search expression for appropriate backend.")) + +(defgeneric expr-> (instance slot-name value) + (:documentation "Create search expression for appropriate backend.")) + +(defgeneric expr-< (instance slot-name value) + (:documentation "Create search expression for appropriate backend.")) + +(defgeneric expr-ends-with (instance slot-name value) + (:documentation "Create search expression for appropriate backend.")) + +(defgeneric expr-starts-with (instance slot-name value) + (:documentation "Create search expression for appropriate backend.")) + +(defgeneric expr-contains (instance slot-name value) + (:documentation "Create search expression for appropriate backend.")) + +(defgeneric expr-and (instance &rest args) + (:documentation "Create search expression for appropriate backend.")) + +(defgeneric expr-or (instance &rest args) + (:documentation "Create search expression for appropriate backend.")) + +(defgeneric expr-not (instance &rest args) + (:documentation "Create search expression for appropriate backend.")) + +(defgeneric select-instances (instance &rest args) + (:documentation "Select instances in backend dependent way")) +(defmacro def-compare-expr (instance-type name expr &key value-format) + `(defmethod ,name ((instance ,instance-type) slot-name value) + (declare (ignore instance)) + (,expr slot-name ,(typecase value-format + (null 'value) + (string `(format nil ,value-format value)) + (t `(,value-format value)))))) +(defmacro def-logical-expr (instance-type name expr) + `(defmethod ,name ((instance ,instance-type) &rest args) + (declare (ignore instance)) + (apply ,expr args))) \ No newline at end of file