Hi,
There is some way to select a limited number of daos without using query-dao?
I think in something like that: the function select-dao accepting some key parameters, like :limit, :offset, :order-by...
(select-dao 'my-entity :limit 100)
to be same as
(query-dao 'my-entity (:limit (:select '* :from 'my-entity) 100))
I think this would be useful in many applications, and allow the developer to write code without SQL.
[]'s
Lucindo
On 9/26/07, Renato Lucindo lucindo@gmail.com wrote:
There is some way to select a limited number of daos without using query-dao?
I think in something like that: the function select-dao accepting some key parameters, like :limit, :offset, :order-by...
SELECT-DAO already accepts an optional argument, i.e. TEST. Adding additional arguments could be done in three ways: (a) by keeping TEST optional and making the rest keyword arguments, (b) by making all arguments optional, or (c) by making all arguments keywords. Approach (a) doesn't seem nice: we mix optional and keyword arguments, and we cannot naturally make e.g. a query with a limit but without a test. (b) doesn't seem sensible, because you would have to memorize the order of the arguments, plus the second part of the argument against (a). (c) breaks older code, which usually is perceived as bad.
(select-dao 'my-entity :limit 100)
to be same as
(query-dao 'my-entity (:limit (:select '* :from 'my-entity) 100))
I think this would be useful in many applications, and allow the developer to write code without SQL.
Well, writing the (:select '* :from... indeed may be annoying. But do you feel it is annoying enough to risk any of the problems I mentioned above?
Cheers,
-- Richard
I think (a) is just a problem in sense the of the mixing optional and keyword arguments because on the select-dao macro the generated sql aways have a 'where' clause, with the default being "where true".
"select .... where true limit ? offset ?" and/or "select .... where true order-by ?" should work.
Off course, the (:limit ...) and (:order-by ...) should only be added to the S-SQL inside select-dao when the keywords paramaters are specified.
On 9/26/07, Ryszard Szopa ryszard.szopa@gmail.com wrote:
On 9/26/07, Renato Lucindo lucindo@gmail.com wrote:
There is some way to select a limited number of daos without using query-dao?
I think in something like that: the function select-dao accepting some key parameters, like :limit, :offset, :order-by...
SELECT-DAO already accepts an optional argument, i.e. TEST. Adding additional arguments could be done in three ways: (a) by keeping TEST optional and making the rest keyword arguments, (b) by making all arguments optional, or (c) by making all arguments keywords. Approach (a) doesn't seem nice: we mix optional and keyword arguments, and we cannot naturally make e.g. a query with a limit but without a test. (b) doesn't seem sensible, because you would have to memorize the order of the arguments, plus the second part of the argument against (a). (c) breaks older code, which usually is perceived as bad.
(select-dao 'my-entity :limit 100)
to be same as
(query-dao 'my-entity (:limit (:select '* :from 'my-entity) 100))
I think this would be useful in many applications, and allow the developer to write code without SQL.
Well, writing the (:select '* :from... indeed may be annoying. But do you feel it is annoying enough to risk any of the problems I mentioned above?
Cheers,
-- Richard
-- http://szopa.tasak.gda.pl/ _______________________________________________ postmodern-devel mailing list postmodern-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/postmodern-devel
Hi Renato,
I guess you are right that the interface of SELECT-DAO is a bit limited, but as Ryszard says it would be hard to extend its functionality in a clean way, and, after playing with a keyword-argument implementation for a bit I concluded that providing all this functionality in such a function would basically be yet another syntax to do the same thing. So my advice is to just use QUERY-DAO for more complex cases.
Regards, Marijn
Hi,
I changed my code to use this function instead of (quey-dao ...)
(defun select-limited-dao (type &key (test t) limit offset order-by desc) (let ((query `(:select * :from ,type :where ,(if (stringp test) `(:raw ,test) test)))) (progn (if order-by (setf query `(:order-by ,query ,order-by))) (if desc (setf query `(:desc ,query))) (if limit (setf query `(:limit ,query ,limit ,(if offset offset ())))) (query-dao type (sql-compile query)))))
But I got a strange error testing this function. The problem is with :desc
(select-limited-dao 'entity :order-by 'column :desc t)
Database error 42601: syntax error at or near "DESC" Query: ((SELECT * FROM entity WHERE true) ORDER BY column) DESC
Then I tried with quey-dao and got the same error:
(query-dao 'entity (:desc (:order-by (:select '* :from 'entity :where t) 'column)))
Database error 42601: syntax error at or near "DESC" Query: ((SELECT * FROM entity WHERE true) ORDER BY column) DESC
I think I'm using :desc in a wrong way.
The query sent to Postgress is: "((SELECT * FROM entity WHERE true) ORDER BY column) DESC"
This quey works: "(SELECT * FROM entity WHERE true) ORDER BY column DESC"
I'm using Postgres 8.2 under OS X 10.4.10 and SBCL 1.0.6
On 9/27/07, Marijn Haverbeke marijnh@gmail.com wrote:
Hi Renato,
I guess you are right that the interface of SELECT-DAO is a bit limited, but as Ryszard says it would be hard to extend its functionality in a clean way, and, after playing with a keyword-argument implementation for a bit I concluded that providing all this functionality in such a function would basically be yet another syntax to do the same thing. So my advice is to just use QUERY-DAO for more complex cases.
Regards, Marijn _______________________________________________ postmodern-devel mailing list postmodern-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/postmodern-devel
Hi,
The documentation is a bit sparse on this, but :DESC should be used on the elements of an :ORDER-BY clause, not on the whole expression, as in:
(:select '* :from 'bozo :order-by (:desc 'age))
Cheers, Marijn
On 9/28/07, some nitwit marijnh@gmail.com wrote:
(:select '* :from 'bozo :order-by (:desc 'age))
Except, of course, that the correct syntax is (:order-by (:select '* :from 'bozo) (:desc 'age))
I changed my code and all seems to be working fine now.
Thanks
On 9/28/07, Marijn Haverbeke marijnh@gmail.com wrote:
On 9/28/07, some nitwit marijnh@gmail.com wrote:
(:select '* :from 'bozo :order-by (:desc 'age))
Except, of course, that the correct syntax is (:order-by (:select '* :from 'bozo) (:desc 'age)) _______________________________________________ postmodern-devel mailing list postmodern-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/postmodern-devel
postmodern-devel@common-lisp.net