From greg at technomadic.org Wed May 9 17:27:36 2012 From: greg at technomadic.org (Greg Pfeil) Date: Wed, 9 May 2012 11:27:36 -0600 Subject: [postmodern-devel] single-key object magic Message-ID: <66BD02CD-2571-4F6A-8FE3-F85840172B5C@technomadic.org> I've made a few changes to Postmodern. They both try to do a little magic in the case where a table has a single primary key column. The first change allows you to use a DAO-OBJECT directly as a parameter, rather than pulling out the key field. EG: > (select-dao 'foo (:= 'bar bar)) instead of having to do > (select-dao 'foo (:= 'bar (id bar))) And the second allows the use of a DAO-CLASS name in the :COL-TYPE field of a slot definition. EG: > (defclass bar () ((id :col-type serial)) (:metaclass dao-class)) > (defclass foo () ((bar :col-type (or db-null bar))) (:metaclass dao-class)) instead of > (defclass bar () ((id :col-type serial)) (:metaclass dao-class)) > (defclass foo () ((bar :col-type (or db-null integer))) (:metaclass dao-class)) These both seem pretty basic, but they mean that you can change the primary key column name or type without having to make changes throughout your code. Also, I see it as a first step toward being able to (eagerly or lazily) auto-populate slots with full objects rather than keys. Does this seem useful, too magical, or already there but I missed it? -------------- next part -------------- A non-text attachment was scrubbed... Name: single-key.patch Type: application/octet-stream Size: 2432 bytes Desc: not available URL: From marijnh at gmail.com Wed May 9 18:30:29 2012 From: marijnh at gmail.com (Marijn Haverbeke) Date: Wed, 9 May 2012 20:30:29 +0200 Subject: [postmodern-devel] single-key object magic In-Reply-To: <66BD02CD-2571-4F6A-8FE3-F85840172B5C@technomadic.org> References: <66BD02CD-2571-4F6A-8FE3-F85840172B5C@technomadic.org> Message-ID: Hello Greg, I'm hesitant to incorporate any 'magic' like this into the core library. It's a matter of aesthetics, but I'm no big fan of this kind of do-what-I-mean API style. I prefer explicitness. If you want to work on a library that does a lot of helpful things under the covers, I think that's best tackled as a layer on top of Postmodern, so that people who want a different approach, or just the basics, don't have to deal with it. Best, Marijn On Wed, May 9, 2012 at 7:27 PM, Greg Pfeil wrote: > I've made a few changes to Postmodern. They both try to do a little magic in the case where a table has a single primary key column. The first change allows you to use a DAO-OBJECT directly as a parameter, rather than pulling out the key field. EG: > >> (select-dao 'foo (:= 'bar bar)) > > instead of having to do > >> (select-dao 'foo (:= 'bar (id bar))) > > And the second allows the use of a DAO-CLASS name in the :COL-TYPE field of a slot definition. EG: > >> (defclass bar () ((id :col-type serial)) (:metaclass dao-class)) >> (defclass foo () ((bar :col-type (or db-null bar))) (:metaclass dao-class)) > > instead of > >> (defclass bar () ((id :col-type serial)) (:metaclass dao-class)) > >> (defclass foo () ((bar :col-type (or db-null integer))) (:metaclass dao-class)) > > > These both seem pretty basic, but they mean that you can change the primary key column name or type without having to make changes throughout your code. Also, I see it as a first step toward being able to (eagerly or lazily) auto-populate slots with full objects rather than keys. > > Does this seem useful, too magical, or already there but I missed it? > > > _______________________________________________ > postmodern-devel mailing list > postmodern-devel at common-lisp.net > http://lists.common-lisp.net/cgi-bin/mailman/listinfo/postmodern-devel > From achambers at mcna.net Sat May 12 20:49:18 2012 From: achambers at mcna.net (Andy Chambers) Date: Sat, 12 May 2012 16:49:18 -0400 Subject: [postmodern-devel] S-SQL extension :if= Message-ID: Hi All, If anyone's interested in using it, I made a little S-SQL extension (def-sql-op :=if (a b) `(,@(case a (:null (sql-expand `(:is-null ,b))) (nil (sql-expand t)) (otherwise (sql-expand `(:= ,a ,b)))))) I find it convenient when writing queries that take optional parameters where if the parameter is not specified, you want to return the row regardless of what value b takes. Does anyone else write little extensions like these? Should we collect them in a contrib? -- Andy Chambers Software Engineer (e) achambers at mcna.net (t) 954-682-0573 CONFIDENTIALITY NOTICE: This electronic mail may contain information that is privileged, confidential, and/or otherwise protected from disclosure to anyone other than its intended recipient(s). Any dissemination or use of this electronic mail or its contents by persons other than the intended recipient(s) is strictly prohibited. If you have received this communication in error, please notify the sender immediately by reply e-mail so that we may correct our internal records. Please then delete the original message. Thank you. From marijnh at gmail.com Mon May 14 19:33:09 2012 From: marijnh at gmail.com (Marijn Haverbeke) Date: Mon, 14 May 2012 21:33:09 +0200 Subject: [postmodern-devel] S-SQL extension :if= In-Reply-To: References: Message-ID: Hi Andy, If you want, you can create a wiki page on the Postmodern github wiki [1] for people to collect such snippets. There's not no huge community around Postmodern, so I'm not sure how much of a market there is for sharing snipptets, but it can't hurt to preserve them somewhere. [1]: https://github.com/marijnh/postmodern/wiki Best, Marijn