Hi,
I have updated weblocks to the latest version, since I've seen that
the postmodern store has become part of the "official" stores. I like
it so far, it simplifies so much the things I want to do.
Also, I propose the following modifications to the
stores/postmodern/postmodern.lisp file:
- class-id-slot-name
dao-keys returns a list of keys that an dao class uses. AFAIK there is
no more than one primary key for each postgresql table, so it should
be ok to car the list, but don't take my word for granted. I hope that
someone else can confirm that.
- find-persistent-objects
Original is great for "straightforward" uses, when you have tables
that are all located in public scheme. But, there are 2 cases where it
is not so, with one of which I had an issue, so that is the main
reason I had to modify the code.
1. Postmodern dao class can have the same name as the postgresql
table, but with :table-name you can put something else, for example:
(defclass mytable ()
((firstcolumn :accessor firstcolumn :column t :initarg firstcolumn))
(:metaclass dao-class)
(:table-name "mysweettable")
(:keys firstcolumn))
So, in this case, the class name is "mytable" but the name of the
actual table in postgresql db is "mysweettable", and there will be an
error "there is no table mytable"...
2. Postmodern dao class supports different scheme, in which case you
must use :table-name as in
(:table-name "myscheme.mytable")
and in that case there is again the problem that class name and table
name differ.
Using dao-table-name both of these issues are solved - if the dao
class has the :table-name defined, it will return that, and if
:table-name is not defined, dao-table-name returns the class name
since it then becomes the value of the :table-name. I have used
explicit package declaration while modifying the code, so you can
remove it if you want to...
I have one question that has been bugging me today while I have been
trying to solve my issues with the postmodern store. It is related to
my still very lacking knowledge of common lisp and CLOS. Let me use
the mytable class above for the example. I have to
(defvar mytable (defclass mytable ..... ))
to use (class-id-slot-name mytable), because for some reason that I
don't understand (class-id-slot-name 'mytable) won't work, in that
case it doesn't reckognize myclass as dao-class but returns the ID as
the ID for weblocks, and not FIRSTCOLUMN. I'm already using unique
sequences in the postgresql tables, and I'd like to reuse them as IDs
for the weblocks objects. As far as I could understand from the few
books and links that I have stuided so far, it is related to the way
lisp works with variables and values, but I still don't quite
understand it.
Below is the diff:
--- original-postmodern.lisp 2011-01-02 00:49:15.746939996 +0100
+++ postmodern.lisp 2011-01-02 00:47:31.696939991 +0100
@@ -117,9 +117,9 @@
;;;;;;;;;;;;;
;;; Utils ;;;
;;;;;;;;;;;;;
-(defmethod class-id-slot-name ((class dao-class))
+(defmethod class-id-slot-name ((class postmodern:dao-class))
;; Returns a list of the column names which compose the primary key.
- (dao-keys class))
+ (car (postmodern:dao-keys class)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -131,7 +131,7 @@
(defmethod find-persistent-objects ((store database-connection) class-name
&key order-by range where
&allow-other-keys)
- (let* ((base-expr `(:select '* :from ,class-name ,@(when where
(list :where where))))
+ (let* ((base-expr `(:select '* :from
,(postmodern:dao-table-name class-name) ,@(when where (list :where
where))))
(order-expr (or `(,@(when order-by
`(:order-by ,base-expr ,(car
order-by)))) base-expr))
(sql-expr (or `(,@(when range
@@ -140,6 +140,6 @@
(defmethod count-persistent-objects ((store database-connection) class-name
&key where &allow-other-keys)
- (let ((sql-expr `(:select (:count '*) :from ,class-name
+ (let ((sql-expr `(:select (:count '*) :from
,(postmodern:dao-table-name class-name)
,@(when where (list :where where)))))
(query (sql-compile sql-expr) :single)))
--
You received this message because you are subscribed to the Google Groups
"weblocks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/weblocks?hl=en.